Reputation: 7450
The topic says it all. I have a dictionary of dictionaries(yes, it's a dictionaryception!) stored in NSUserDefaults
. For some strage reason I get SIGABRT at main.m just right after setting an object to the dictionary. Here's the code:
planDict = [[NSUserDefaults standardUserDefaults]objectForKey:[NSString stringWithFormat:@"Plan_%@", self.planName]];
pageOne = [planDict objectForKey:@"Page_1"];
pageTwo = [planDict objectForKey:@"Page_2"];
pageThree = [planDict objectForKey:@"Page_3"];
[pageOne setObject:@"The Object" forKey:@"First Key"];
[pageOne setObject:@"The Other Object" forKey:@"Second Key"];
//other setters
I've debugged it and it went well till the line [pageOne setObject:@"TheObject" forKey:@"First Key"];
. When I stepped over it just crashed(SIGABRT in main.m).
Here's the log right before the crash:
(gdb) po planDict
{
"Page_1" = {
};
"Page_2" = {
};
"Page_3" = {
};
}
(gdb) po pageOne
{
}
(gdb) po pageTwo
{
}
(gdb) po pageThree
{
}
Any help would be appreciated, thank you.
Upvotes: 1
Views: 638
Reputation: 1800
I think the real problem is in saving the dictionaries, have you saved mutable dictionary? you are being given an immutable dictionary, so you have to create a mutable copy to it.
Upvotes: 1
Reputation: 565
The dictionary returned by asking NSUserDefaults will be an immutable dictionary, as will any dictionaries within dictionaries etc.
So SETTING an object on the immutable dictionary will indeed throw a SIGABRT error as the object returned does not understand the method you sent to it.
You will want to create a mutable copy of the dictionary instead, and make a mutable copy of each contained dictionary within that dictionary.
Hope that sorts out your error.
Upvotes: 4