Xcode 8 Beta - Simulator won't write to NSUserDefaults

Is anyone seeing this as well?


If I run a simple app (just create a Single View Application) in an iPhone 6s Simulator (10), NSUserDefaults won't work.


Example code:


NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];

NSString* testString = @"Test";

NSData* testData = [testString dataUsingEncoding:NSUTF8StringEncoding];

[userDefaults setObject:testData forKey:@"test"];

[userDefaults synchronize];

NSData* retrievedData = [userDefaults objectForKey:@"test"];


At the end retrievedData is nil


I am inclined to create a radar for this, but maybe I am doing something wrong... ?

Replies

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.

Thanks for that. I can confirm it worked for me.


Looks like this issue was reported in a WWDC release of XCode, it does NOT appear to be in the just-released beta release notes:


http://adcdownload.apple.com/WWDC_2016/Xcode_8_beta/Release_Notes_for_Xcode_8_beta.pdf


See also:

https://forums.developer.apple.com/message/143878#143878

odd i rebooted my mac and it still doesnt work, i suppose ill just wait


Edit

Nvm its working, i did so many things to try to fix it , that i confused myself ! haha