Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Array From .Plist

I'm trying to load my array from an array in my .Plist but its not working.

The plist looks like this:

enter image description here

This is the code I'm using:

NSString *path = [[NSBundle mainBundle]pathForResource:@"DiseasePropertyList" ofType:@"plist"];
NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.myArray = rootLevel;
[rootLevel release];
like image 716
Jon Avatar asked Aug 08 '11 01:08

Jon


2 Answers

Try this. Please change file name. It works fine.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *recentFilePath = [documentsDirectory stringByAppendingPathComponent:@"recent.plist"];
NSArray *history = [NSArray arrayWithContentsOfFile:recentFilePath];
like image 117
ChangUZ Avatar answered Sep 21 '22 00:09

ChangUZ


Your plist is actually a dictionary. The array is the object of that dictionary for key "Array". You can make the plist into an array in Xcode 4 by selecting "Array" and cutting (CMD-x), and then pasting into the empty plist (CMD v).

like image 41
Andrew Toth Avatar answered Sep 22 '22 00:09

Andrew Toth