Ok, so I've been reading the Kochan Objective-C book and I have a question. I'm right now developing an app where I need to utilize the use of a struct with several NSMutable arrays. The examples in the Kochan book use struct examples that involve the int, double, and struct (adding a struct within a struct). I was wondering about the process you would go about putting a NSMutableArray in a struct. If you look at the sample below, I am wondering if I need to declare NSMutableArray *dataList in the struct or would I do something like Code #2 below. Now I know you have to list the data type, so if I did something like code #2, what data type would I use for dataList? Would it be NSMutableArray since dataList is a pointer to a NSMutableArray? I have been reading more on pointers, so if I've used the wrong terminology or said something wrong, please point it out in a "constructive criticism" sort of way. Thank you so much in advance for the help. I have one last general question. I hope this makes sense. If I am declaring an array to be used as a pointer in the "instance variable" section of the interface for example, would I declare, allocate, and initialize it all at the same time in the interface section of the header file or elsewhere? If somewhere else, could you give me any pointers/tips on what your programming experience has taught you?
CODE #1:
struct data{
int data1;
double data2;
NSMutableArray *dataList;
};
CODE #2:
NSMutableArray *dataList = [[NSMutableArray alloc] initWithCapacity:0];
struct data{
int data1;
double data2;
NSMutableArray dataList;
}
CODE #1:
struct data{
int data1;
double data2;
NSMutableArray *dataList;
};
CODE #2:
NSMutableArray *dataList = [[NSMutableArray alloc] initWithCapacity:0];
struct data{
int data1;
double data2;
NSMutableArray dataList;
}