antonio antonio - 1 year ago 972
Objective-C Question

iOS 10, NSUserDefaults Does Not Work

I try to write/read values to/from

[NSUserDefaults standardUserDefaults]
, but it seems not to work. My code is:

[[NSUserDefaults standardUserDefaults] setObject:@"sampleString" forKey:@"sampleKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSString *defaultsValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"sampleKey"];
return defaultsValue;

This code returns
, for Xcode 8.0 beta and iPhone 6s (10.0) simulator.
However it returns
for Xcode 8.0 beta and iPhone 6s (9.1) simulator

I am testing my app with the new systems. Am I doing something wrong? Or is there a workaround for that? Or is it just a "beta" issue?

Answer Source

I just had the same problem. There seems to be an issue with NSUserDefaults when first running the iOS8 or 9 simulator and then the iOS10 simulator. Rebooting the mac solved the issue for me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download