我正在为 iOS 编程,并使用 ARC。
我正在尝试使用 c 数组作为属性,但它报告错误。
@property (strong, nonatomic)NSString *mappingTable[70][254];
错误是 “Property cannot have array or function type NSString *[70][254]”
。我怎么解决这个问题?如何将 c 数组声明为属性?
注意:
这是一个二维数组,我认为只使用 c 数组更容易,所以我没有使用 NSArray。
最佳答案
令人惊讶的是,这还没有被建议,但您可以将 c 数组存储在 NSData 对象中。我只是用这个方法来存储一个帧数组。
@property (nonatomic) NSData *framesArray;
// Create and initialize your c-style frames array
CGRect frames[numberOfFrames];
...
self.framesArray = [NSData dataWithBytes:frames length:(sizeof(CGRect) * numberOfFrames)];
// To Access the property
NSUInteger arraySize = [self.framesArray length] / sizeof(CGRect);
CGRect *frames = (CGRect *) [self.framesArray bytes];
关于ios - C 数组作为 iOS 中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15202041/