3

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!

pkamb
  • 33,281
  • 23
  • 160
  • 191
Richard
  • 1,249
  • 16
  • 25
  • Have you posted this as a bug to Apple? Logged in in the developer forums? – drekka Jun 15 '16 at 00:20
  • 2
    Dev forums weren't working, and anyway most people search stackoverflow first. But it looks like it is a documented issue, albeit with a pretty ugly workaround. I'll post the answer. – Richard Jun 15 '16 at 00:29

1 Answers1

8

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.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Richard
  • 1,249
  • 16
  • 25
  • 1
    Interestingly I can NOT find this note in the published release notes for either iOS 10 or XCode 8, which is where I looked first for this issue. The reboot DOES resolve this issue however. – Richard Jun 15 '16 at 00:40
  • This is noted as fixed in XCode 8 beta 2, but I have not yet tried it. – Richard Jul 08 '16 at 02:09