I am trying to update a boolean value in a plist dictionary in an iphone app. The plist dictionary contains several strings and two boolean values. Below is my current code.
I first define the plist and then define the NSMutableDictionary. When the third line of code below is run I get an error.
NSString *plistFile = [[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:plistFile];
[[dict objectForKey:@"Day 1"] setBool:TRUE forKey:@"Bookmarked"];
The error highlights the return statement below with the following error "Thread 1: Program received signal: "SIGABRT"
int main(int argc, char *argv[])
{ @autoreleasepool{
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Any help you can provide will be greatly appreciated. Thanks so much in advance.
Just because dict
is mutable doesn't mean that it's sub dictionaries are. Also NSMutableDictionary
has no setBool:forKey:
method.
NSMutableDictionary *subDict = [[dict objectForKey:@"Day 1"] mutableCopy];
[subDict setObject:[NSNumber numberWithBool:TRUE] forKey:@"Bookmarked"];
[dict setObject:subDict forKey:@"Day 1"];