views:

58

answers:

2

I have NSArray in Objective C, which store int only. How can I convert it to C array? Thanks.

My Objective C array:

NSArray *myArray = [[NSArray alloc] initWithObject:@"1", @"4", @"8", nil];
A: 

Allocate a chunk of memory using malloc to hold enough of the items (in this case, NSString*s and iterate over the NSArray, adding each item (and retaining each item) into an appropriate position in the c array.

Don't forget in doing this, you will have to send a release message to each member in the c array when you're done with it, before you also have to free() the array itself.

jer
A: 

I guess you cannot explicitly since an NSArray encapsulates a C array, but an array of pointers to the objects referenced. So the better you can get is to retrieve (in reality copy) that array of pointers. If you want to get the value of the objects you need to 'query' them for their values, have a look here

rano