How to read data structure from .plist file into NSArray How to read data structure from .plist file into NSArray ios ios

How to read data structure from .plist file into NSArray


NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"league" ofType:@"plist"];contentDict = [NSDictionary dictionaryWithContentsOfFile:plistPath];

That answer is correct - are you sure that your file is in the app? Did you add it to your project, and check to see if it gets copied into your app bundle? If not, it might be the file was not added to the target you are building, an easy mistake to make especially if you have multiple targets.


Use this code if the plist is in the resources folder of the project.

  NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"league"    ofType:@"plist"]; contentArray = [NSArray arrayWithContentsOfFile:sourcePath];

If the plist is inside the document directory of the app use this:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;NSString *plistName = @"league";NSString *finalPath = [basePath stringByAppendingPathComponent:                        [NSString stringWithFormat: @"%@.plist", plistName]];contentArray = [NSArray arrayWithContentsOfFile:finalPath];


I had this issue but it wasn't working because I was putting the results from the pList into an array where it should have been a dictionary, i.e

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"VehicleDetailItems" ofType:@"plist"];NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];