This question already has an answer here:
这个问题在这里已有答案:
- Declaring, Properties, Synthesizing, and Implementing int[] array in Objective C 5 answers
在Objective C 5答案中声明,属性,合成和实现int []数组
How to declare a C array of integers as a property on an objective-c class?
如何将一个C数组的整数声明为objective-c类的属性?
1 个解决方案
#1
6
@property (nonatomic, assign) int *array;
...
// somewhere in your code
int *gg = malloc(10 * sizeof(int));
gg[1] = 1;
gg[0] = 2;
self.array = gg;
UPDATE:
This is heap based array now to make sure it will not be deallocated.
But don't forget to free it in deallocfree(self.array)
这是基于堆的数组,现在确保它不会被释放。但不要忘记在dealloc free(self.array)中释放它
#1
6
@property (nonatomic, assign) int *array;
...
// somewhere in your code
int *gg = malloc(10 * sizeof(int));
gg[1] = 1;
gg[0] = 2;
self.array = gg;
UPDATE:
This is heap based array now to make sure it will not be deallocated.
But don't forget to free it in deallocfree(self.array)
这是基于堆的数组,现在确保它不会被释放。但不要忘记在dealloc free(self.array)中释放它