Why won't my app run in XCode 8 beta (8S128d)

2019-02-18 19:36发布

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!

1条回答
一夜七次
2楼-- · 2019-02-18 20:10

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.

查看更多
登录 后发表回答