ios - C 数组作为 iOS 中的属性

标签 ios objective-c cocoa-touch

我正在为 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/

相关文章:

ios - 为什么 UISlider 更新 Cocoa-Touch 中的值很慢?

javascript - 使用现有 DER/PEM key 在 Javascript 中进行 RSA 加密

ios - 选择日期后如何禁用 UIDatePicker?

iphone - App Store 分发配置文件与开发配置文件

iOS - 如何以编程方式为控件设置自定义类

objective-c - 关于 "Semantic Issue"的编译器警告——如何解决?

ios - 需要帮助解除模态呈现的 ViewController 并从 UINavigationController 弹出 ViewController

iphone - UIImageView 边框颜色

ios - 如何在 UIScrollView 中将图像彼此相邻放置?

objective-c - NS对象 : on the heap or the stack?