开发者

managedObjectContext seems to delete my NSUserDefault

saving the managedObjectContext seems to eat the NSUserDefault

NSString *defaultSiteUrl = [[NSUserDefaults standardUserDefaults] objectForKey:kSelectedSiteUrlKey];
NSLog(@"the default site url is: %@", defaultSiteUrl);

if (![[managedObjectContext] save:&error]) {
    NSLog(@"Error saving entity: %@", [error localizedDescription]);
}

NSStr开发者_如何学Going *defaultSiteUrl2 = [[NSUserDefaults standardUserDefaults] objectForKey:kSelectedSiteUrlKey];
NSLog(@" the default site url is: %@", defaultSiteUrl2);

Result in the console:

2011-05-10 15:26:40.710 Moodle[44566:207] the default site url is: http://jerome.moodle.local/~jerome/Moodle_iPhone
2011-05-10 15:26:40.717 Moodle[44566:207] the default site url is: (null)

What could cause this issue? In which way is NSUserDefaults related with ManagedObjectContext?

Note:

  • To let you know my application: I'm developping a Moodle app. This piece code is on a screen displaying a list of courses. I use [[NSUserDefaults standardUserDefaults] synchronize] when I set the userdefault on a "site settings" screen. So I guess it's well saved

  • The piece of code works (the user defaults are not deleted by the "save manageObjectContext") if I restart the simulator before going to the course listing screen straight after setting the user default.


You must initialize the NSUserDefaults value by [NSUserDefaults registerDefaults:appDefaults], using synchronize method for instiliaztioan could destroy you user defaults, NOTE, it's nothing to do with core data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜