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.