Reputation: 987
I am using objective c to create a struct holding a variable length array. I know you can create an array of length n like so:
double array[n];
And i also believe in c++ you can declare:
vector<double> array;
where you do not have to declare the array length. Is there any way to do something similar in objective c? I am using ARC.
Thanks in advance, Ben
Upvotes: 2
Views: 1571
Reputation: 11839
You just need to create an NSMutableArray like-
NSMutableArray *myArray = [NSMutableArray array];
[myArray addObject:....];// Add as many object as you want.
You just need to take care of one thing while creating variable length array, don't add nil as object, as nil is just to signify the end of the variable-length argument list.
EDIT - Might be following will help you - In this way you can define objective c data types in struct-
typedef struct{
int numInputs;
__unsafe_unretained NSMutableArray *array;
} Pin;
Upvotes: 3