This is an issue that will affect many apps, and can be found in Xcode 8 beta (8S128d). This is the first beta, although it is not labelled beta 1.
The issue is with NSUserDefaults; it doesn't work. Here's the code, maybe put it in application:didFinishLaunchingWithOptions:
.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:@"hello world" forKey:@"TEST"];
[defaults synchronize];
NSString * oops = [[NSUserDefaults standardUserDefaults] valueForKey:@"TEST"];
NSLog(@"default = %@", oops);
In Xcode 7 and earlier, this code works as expected: the value of oops
is "hello world".
In Xcode 8, the value of oops
is nil
.
That's pretty major!
Found the answer: https://forums.developer.apple.com/message/143155#143155
If you've used Xcode 7 or earlier, you need to reboot the Mac before running the iOS 10 simulator.
From the release notes:
WWDC Seed: Running multiple iOS simulators can cause NSUserDefaults to not work
Running an iOS 8 or 9 simulator followed by an iOS 10 simulator will cause NSUserDefaults to stop working in the simulator. This can be worked around by rebooting the host Mac.