The pList Dilemma – xCode Gotcha


Why does the following code return no objects in the array.


NSString *path = [[NSBundle mainBundle] pathForResource:@"stations" ofType:@"plist"];
NSMutableArray* anns = [[NSMutableArray alloc] initWithContentsOfFile:path];

Here is a screen shot from within Xcode at the pList editor.

They seem the same Jim !

The problem stems from creating the pList directly in Xcode.

Here we can see a text view of the two versions of the file, subtle but critical difference.

There seems to be an extra tag here !

So when we try and initialise the NSMutableArray with the contents of the file it is only finding dictionary entries, therefore fails and we end up with an empty array.

So a word to the wise, when you are creating pList files directly via xCode, make sure they are set up correctly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: