UserDefaults Never Persists Any Data

Originator:paul
Number:rdar://26799886 Date Originated:6/14/2016
Status:Open Resolved:
Product:iOS SDK Product Version:10 beta 1
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
NSUserDefaults does not persist any data. I’ve attached a sample project with unit tests that demonstrate this issue.

Steps to Reproduce:
1. Create a NSUserDefaults object (via initWithSuiteName:) or access the .standardUserDefaults().
2. Set a value on it for a specified key.
3. Attempt to retrieve the value from it using that key.

Expected Results:
The value that was set in NSUserDefaults would be retrieved when using the same key.

Actual Results:
NSUserDefaults returns nil when using the same key.

Regression:
This does not occur when the app is built using the iOS 9 SDK.

Comments

In case you didn't already figure this out, you gotta call synchronize to actually persist the data to disk. http://stackoverflow.com/a/2622940/2125328

Sample Project

https://github.com/paulrehkugler/NSUserDefaultsTest


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!