In Objective-C, how can I define a C array of 'unknown size' as an instance variable, and later populate the array?
(Background) : I have a class in Objective-C which handles loading game data. The data is stored in an array of C structs, contained in an external datafile. I can load in the array and access it, but I need it to be accessible throughout the class. What I'm trying to do is declare an 'empty' array in my instance variables and then (when loaded) point this empty array or replace it with the one I've loaded in.
This is how I'm loading in my data...
FILE *fptr = NULL;
fptr = fopen([path cStringUsingEncoding:NSUTF8StringEncoding], "r");
// Create an empty array of structs for the input file with known size
frame2d newAnimationData[28];
// Read in array of structs
fread(&newAnimationData, sizeof(newAnimationData), 1, fptr);
fclose(fptr);
So this code works fine to recreate my array of frame2d structs - I just need to know how I can use this as an instance variable.
Any help is appreciated, thanks.