I have an NSDictionary where each key points to an array. I later want to merge all of the values into one array. Is there a way to use the API to do something more efficient than say:
NSArray *anArray = [someDictionary allValues]; NSMutableArray *newArray = [NSMutableArray array]; start outter loop on anArray start inner loop on objects in anArray add objectAtIndex to newArray
Any subclass of NSArray must override the primitive instance methods count and object (at:). These methods must operate on the backing store that you provide for the elements of the collection. For this backing store you can use a static array, a standard NSArray object, or some other data type or mechanism.
NSArray *array1 = [NSArray arrayWithObjects:@"one", @"two", @"three", nil]; NSArray *array2 = @ [@"one", @"two", @"three"]; The most flexible ways to sort an array is with the sortedArrayUsingComparator: method.
NSArray creates static arrays, and NSMutableArray creates dynamic arrays. You can use arrays when you need an ordered collection of objects. NSArray is “toll-free bridged” with its Core Foundation counterpart, CFArray. See Toll-Free Bridging for more information on toll-free bridging.
Remember that NSArray is the public interface for a class cluster and what this entails for your subclass. You must provide the storage for your subclass and implement the primitive methods that directly act on that storage. Before making a custom subclass of NSArray, investigate NSPointerArray and the corresponding Core Foundation type, CFArray.
Just use [newArray addObjectsFromArray:anArray];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With