I have a plist containing an array, with a number of items that I wan't maintained in a particular order.
When I create an NSArray from the plist, will the array have the objects in the same order as the plist? For example. If I execute the code like the following, will the array have the items in the same order as the plist?
NSMutableDictionary* plistDictionary = [self someMethodToReadThePlistAsDictionary:plistName];
NSArray* array = [plistDictionary objectForKey:@"arrayKey"];
Is there any documentation where I can verify this? In practice it seems to be the case, but I would like to verify it somehow.
EDIT: I seem to be getting down votes for this question, so let me clarify: I am fully aware that an array maintains insertion order. My question has to do with "plists", since I am unaware of what happens to a plist when it becomes an object.
NSArray creates static arrays, and NSMutableArray creates dynamic arrays.
The main difference is that NSArray is for an ordered collection and NSSet is for an unordered collection. There are several articles out there that talk about the difference in speed between the two, like this one. If you're iterating through an unordered collection, NSSet is great.
The NSMutableArray class declares the programmatic interface to objects that manage a modifiable array of objects. This class adds insertion and deletion operations to the basic array-handling behavior inherited from NSArray .
The answer is yes, the order of the elements of an array will be maintained - because an array is an ordered collection of items, just like a string is an ordered sequence of characters...
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