您可能需要完整类型,即
@property (nonatomic) BOOL boolArray [100];
[100] 是重要的类型信息,而不仅仅是指示要分配多少空间。
另外,我认为该属性将被视为无法分配的const BOOL *,因此它可能必须是readonly。正确的做法可能是将此设置为只读,这意味着 Thins 将获取数组指针,然后将其下标以分配给数组的成员。
或者,您可以为此使用NSArray,但这需要您将NSNumbers 与boolVaules 一起使用,这更像是一个恶作剧。
更新
实际上,愚蠢的编译器出于某种原因不喜欢 []。试试这个:
@interface TestClass : NSObject {
const BOOL *boolArray;
}
@property (nonatomic, readonly) const BOOL *boolArray;
@end
@implementation TestClass;
- (const BOOL *)boolArray {
if (!boolArray)
boolArray = malloc(sizeof(BOOL) * 100);
return boolArray;
}
- (void)dealloc {
[super dealloc];
free((void *)boolArray);
}
@end
另一个更新
这样编译:
@interface TestClass : NSObject {
BOOL boolArray[100];
}
@property (nonatomic, readonly) const BOOL *boolArray;
@end
@implementation TestClass;
- (const BOOL *)boolArray {
return boolArray;
}
@end
这是一个奇怪的问题。我希望编译器能准确解释它的不满意之处,例如“无法声明具有数组类型的属性”之类的。
还有一个更新
看到这个问题:Create an array of integers property in Objective C
显然,根据 C 规范,数组不是“普通旧数据”类型,Objective-C 规范只允许您声明 POD 类型的属性。假设这是 POD 的定义:
http://www.fnal.gov/docs/working-groups/fpcltf/Pkg/ISOcxx/doc/POD.html
但读起来似乎是一个 POD 数组就是一个 POD。所以我不明白。