Objective-C. Property for C array

后端 未结 4 1106
不思量自难忘°
不思量自难忘° 2020-12-18 09:01

I need something like this:

@property (nonatomic, retain) int field[10][10];

but this code doesn\'t work. How to replace it? I need both se

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-18 09:28

    It s pretty simple.

        @interface MyClass
        {
            int _fields[10][10]; 
        }
    
        @property(readonly,nonatomic) int **fields;
    
        @end
    
        @implementation MyClass
    
        - (int *)fields
        {
            return _fields;
        }
    
        @end
    

    Use readonly in property as it is a fixed pointer, which you wont be changing, which doesn't mean that you can't modify the values in the array.

提交回复
热议问题