Objective-C的。物业对C数组 [英] Objective-C. Property for C array
本文介绍了Objective-C的。物业对C数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要的东西是这样的:
I need something like this:
@property (nonatomic, retain) int field[10][10];
但这种code不起作用。如何更换呢?我同时需要setter和getter方法
but this code doesn't work. How to replace it? I need both setter and getter methods
推荐答案
您可以做到这一点,如果你换一个结构数组。结构是在@property符号(见的CALayer的CGRect界限,例如)的支持。
You can do it if you wrap the array in a struct. Structs are supported in @property notation (see CGRect bounds on CALayer, for example).
首先定义你的结构:
typedef struct {
int contents[10][10];
} TenByTenMatrix;
然后,在你的类接口,你可以这样做:
Then, in your class interface, you can do:
@property (assign) TenByTenMatrix field;
请注意,在这种情况下,你只能得到或使用该属性设置整个阵列。所以,你不能这样做。
Note that in this case, you can only get or set the whole array using the property. So you can't do
self.field.contents[0][0] = 1;
您必须做
TenByTenMatrix temp = self.field;
temp.contents[0][0] = 1;
self.field = temp;
这篇关于Objective-C的。物业对C数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文