Reputation: 1475
I have a method:
#define ROOT_ASSETS_PATH @"/assets/"
...
-(NSMutableDictionary*) getContentsOfPlist{
NSString *pageContentPlistPath = [[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent: ROOT_ASSETS_PATH] stringByAppendingPathComponent:@"content.plist"];
NSMutableDictionary *mDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:pageContentPlistPath];
return mDicitonary;
}
On the simulator. this returns a dictionary. On the iPad, it returns nil. Made sure the extension case matches that in the call as well.
Any ideas?
Upvotes: 0
Views: 1621
Reputation: 1475
The issue was case after all. Case of the filename didn't match the case I put in the parameter. OSX doesn't care, but the iPad does.
Upvotes: 2
Reputation: 13783
+ (id)dictionaryWithContentsOfFile:(NSString *)path
Parameters
path
A full or relative pathname. The file identified by path must contain a string representation of a property list whose root object is a dictionary.
Return Value
A new dictionary that contains the dictionary at path, or nil if there is a file error or if the contents of the file are an invalid representation of a dictionary.
So, you have to set a full path to your file (or an appropriate relative path)
Note also that the app bundle is read-write on Simulator but read-only on device.
Upvotes: 0
Reputation: 573
Also it is good idea to use:
[NSPropertyListSerialization propertyListWithData:options:format:error:]
Instead of direct NSDictionary initialization. If something will fail, it should return a nice error for you.
Upvotes: 0
Reputation: 1840
Try removing the slashes in your #define. stringByAppendingPathComponent will add the slashes for you. Not sure why this would work in the Simulator.
Upvotes: 0