为什么我的应用程序 运行 Xcode 8 beta (8S128d)

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

这是一个会影响许多应用程序的问题,可以在 Xcode 8 beta (8S128d) 中找到。这是第一个测试版,虽然它没有标记为测试版 1。

问题出在 NSUserDefaults 上;它不起作用。这是代码,也许把它放在 application:didFinishLaunchingWithOptions:.

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:@"hello world" forKey:@"TEST"];

[defaults synchronize];

NSString * oops = [[NSUserDefaults standardUserDefaults] valueForKey:@"TEST"];
NSLog(@"default = %@", oops);

在 Xcode 7 及更早版本中,此代码按预期工作:oops 的值为“hello world”。

在Xcode8中,oops的值为nil

这很重要!

找到答案:https://forums.developer.apple.com/message/143155#143155

如果您使用过 Xcode 7 或更早版本,则需要在 运行 iOS 10 模拟器之前重新启动 Mac。

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.