Objective c 为什么Xcode告诉我这个变量未声明?

Objective c 为什么Xcode告诉我这个变量未声明?,objective-c,cocoa,xcode,Objective C,Cocoa,Xcode,我在Xcode中遇到以下错误,我知道我需要声明filteredChildren,所以我尝试将行NSArray*filteredChildren添加到头文件中,但这只会让事情变得更糟。我需要向delcarefilteredChildren的标题中添加什么代码 您的标题可能应该如下所示: @interface SomeClass { NSArray *filteredChildren; // this should fix the compiler error } // If the fi

我在Xcode中遇到以下错误,我知道我需要声明
filteredChildren
,所以我尝试将行
NSArray*filteredChildren
添加到头文件中,但这只会让事情变得更糟。我需要向delcare
filteredChildren
的标题中添加什么代码


您的标题可能应该如下所示:

@interface SomeClass {
    NSArray *filteredChildren; // this should fix the compiler error
}

// If the filteredChildren method is public, add this declaration as well to prevent compiler warnings
- (NSArray *)filteredChildren;

@end

看不到代码,但要确保在函数之后打开和关闭所有的花括号,要知道这可能会导致问题,并且可以很容易地在大型项目中完成

int a = 1;
void example () 
{ if (exampleVar = 1 {
a = 2; // not declared error
}


int a = 1;
void example () 
{ if (exampleVar = 1 {
a = 2; // should be declaring
}
}
检查所有头文件和类层次结构,确保没有两次声明头或同一个类,这可能会在创建类实例并使其未声明时生效


如果不是这种情况,请尝试清理/重置编译后的数据。

您也可以发布头文件吗?您在头文件中的什么位置添加了头文件?请编辑您的问题以显示添加了声明的代码。另外,添加声明后会出现哪些错误?