Using NSMutableArray to Store Data
3 answers
Yes, you can store any type of object in one of the NSArray classes. The only difficulty lies in conceptually considering how to access this data structure; complex nesting of arrays into arrays can be difficult and error prone. Make sure your needs are not better addressed by another data structure or custom class.
+3
source to share
Yes. You can use the following (huge) line of code:
NSMutableArray * completeArray =
[NSMutableArray arrayWithArray:
[[myArray objectAtIndex:0] arrayByAddingObjectsFromArray:
[myArray objectAtIndex:1]]];
edit: Assuming that's myArray
defined like this:
NSArray * stringArray = [NSArray arrayWithObjects:
@"one", @"two", @"three", nil];
NSArray * otherArray = [NSArray arrayWithObjects:
someObj, otherObj, thirdObj, nil];
NSArray * myArray = [NSArray arrayWithObjects:
stringArray, otherArray, nil];
The line of code posted above will give you one big one NSMutableArray
that contains:
@"one, @"two", @"three", someObj, otherObj, thirdObj
0
source to share