您需要初始化您的字典并稍后将其设置为对象。这种方式有效,它与您的示例相同,但只是正确初始化。
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"someValue", @"someKey", nil];
[defaults setObject:dict forKey:@"slovnik"];
[dict release];
NSLog(@"READ: %@", [defaults objectForKey:@"slovnik"]);
NSMutableDictionary *newDict = [[NSMutableDictionary alloc] initWithDictionary:[defaults objectForKey:@"slovnik"]];
NSLog(@"READ2: %@", newDict);
现在我可以登录控制台并且应用程序不会崩溃:
2012-04-12 08:47:55.030 Test[12179:f803] READ: {
someKey = someValue;
}
2012-04-12 08:47:55.031 Test[12179:f803] READ2: {
someKey = someValue;
}