Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is NSArray / NSMutableArray order guaranteed when reading array from plist?

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.

like image 473
xcoder Avatar asked Jan 31 '12 09:01

xcoder


People also ask

What is difference between NSArray and NSMutableArray?

NSArray creates static arrays, and NSMutableArray creates dynamic arrays.

What's a difference between NSArray and NSSet?

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.

What is NSMutableArray?

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 .


1 Answers

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...

like image 189
CRD Avatar answered Dec 05 '22 20:12

CRD