NSUserDefaults in iOS 10, xcode 8 beta

A really simple method i used to set and get nsuserdefaults doesnt seem to be working in iOS10, i have only tried in the simulator so it maybe only simulator related.


See a simple code snippet for testing below


NSInteger value = 1;

NSUserDefaults *test = [NSUserDefaults standardUserDefaults];

[test setInteger:value forKey:@"hello"];

[test synchronize];

NSInteger val = 0;

val = [test integerForKey:@"hello"];


I would assume val would equal 1, but its still 0. I use nsuserdefaults for many settings and they all do the same.

Also it seems nslog doesnt seem to be outputting anything to the output window , unless im missing something.

Replies

I also tested on simulator and found there is no Preferences plist existing "Library/Preferences" folder. So without that plist, all NSUserDefaults functions won't work. Seems to be bug.

Documented bug, apparently.


This happens if you try and run an iOS 10 simulator after running an earlier XCode 7 simulator. Need to reboot the Mac and go straight to XCode 8 to resolve.


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

Thx. Reboot Mac resolves the issue.