When I add an plists-file to my XCode project, my iPad app can’t seem to read it.
For example: I have massCategories.plist inside my project’s folder (where the xproj-file lives). Inside my plist is the following code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Item 1</key>
<dict>
<key>Key 1</key>
<string>Value 1</string>
<key>Key 2</key>
<string>Value 2</string>
</dict>
<key>Item 2</key>
<dict>
<key>Key 3</key>
<string>Value 3</string>
<key>Key 4</key>
<string>Value 4</string>
</dict>
</dict>
</plist>
Inside my ViewController I have the following method:
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *plistData = [mainBundle pathForResource:@"MassCategories" ofType:@"plist"];
NSArray *massCategories = [[NSArray alloc] initWithContentsOfFile:plistData];
// breakpoint
}
When running (and “pausing” at the breakpoint), massCategories contains nil.
Adding the plist file to another folder doesn’t seem to work (or I must be using the wrong folders, which is well possible :-)).
Any suggestions?
Got it!
Just update the plist such that the main element is an array (just as I should’ve expected when trying to import it as an array):