Search code examples
iphoneobjective-cxcodensarrayplist

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];

Solution

  • 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];