Reputation:
I'm trying to load the following plist into an NSArray:
Here is the code I'm using to load the data:
// Load the data from the plist file
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"MyData" ofType:@"plist"];
NSArray *myArray = [[NSArray alloc] initWithContentsOfFile:filepath];
However when I place a breakpoint after the data has been loaded I notice that the array is empty. Please can someone help me understand what's going wrong?
Upvotes: 1
Views: 1233
Reputation: 799
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"name.plist"];
NSArray *plistData = [NSArray arrayWithContentsOfFile:finalPath];
Upvotes: 1
Reputation: 3000
Your plist file has a dictionary that contains an array. Try this
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:filePath];
NSArray *array = [[NSArray alloc]initWithArray:[dict objectForKey:@"Root"]];
Upvotes: 2
Reputation: 2605
Could you try loading it into a NSDictionary and asking for the [ objectForKey:@"Root"]
inside it ?
As far as I remember, property lists are key / value maps and your array is just one of those values.
Upvotes: 5