I’m having problem reading from a plist file
I have the Settings.plist file saved in my project (tried both in and out of the Resources folder)
And none of the method google and stackOverFlow has to offered worked. I have no idea what I’m missing.
the code is:
NSString *pListPath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
NSMutableDictionary *settings = [[[NSMutableDictionary alloc] initWithContentsOfFile:pListPath] retain];
BOOL touch = [[settings objectForKey:@"Touch"] boolValue];
NSLog(@"%@",touch ? @"TOUCH IS YES" : @"TOUCH IS NO");
I’ve tried many different methods of getting the *plistPath, NSBundle, just a string with the file name. also tried NSMutabelDictionary, regulat NSDictionary, NSArray, NSMutableArray
Nothing seems to work.
Tried setting the plist first line into a Root dictionary, still no luck..
Any help would be apreciated..
Settings.plist has a single value Touch and its key is YES
Thanks alot!
EDIT:
Here’s the plist:
<?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>Root</key>
<dict>
<key>Touch</key>
<true/>
</dict>
</dict>
</plist>
Your plist contains a top-level dictionary with one key, “
Root”. The value for that key is another dictionary with one key, “Touch”.Try this:
or this (slightly slower):