1

How to declare a C array of integers as a property on an objective-c class?

Nicolas Manzini
  • 8,123
  • 6
  • 60
  • 78

1 Answers1

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 dealloc free(self.array)

Basheer_CAD
  • 4,858
  • 23
  • 36