Cannot store Dictionary in NSUserDefaults in iOS8
Originator: | tmk.szlc | ||
Number: | rdar://18403298 | Date Originated: | |
Status: | Open | Resolved: | |
Product: | iOS SDK | Product Version: | 8.0 |
Classification: | Data Loss | Reproducible: | Always |
Summary: Storing Dictionary in NSUserDefaults does nothing, after dictionary object is saved and NSUserDefaults is synchronized attempt to read stored value ends with nil. There is no key and value stored before. This works correctly on iOS 7. Tested on iPad 3 with iOS7. Steps to Reproduce: 1. Open attached example app 2. Tap "Save YES" // ["a": "1"] should be in user defaults 3. Label should update to "Value set to: true" but it doesn't. Log from console is saying: registered defaults: [a: 0] loaded: [a: 0] to be saved: [a: 1] loaded: [a: 0] /// nothing has been saved, still registered defaults are fetched 4. Replace save(), read() and registerDefaults() with save_fixed(), read_fixed(), registerDefaults_fixed() - These method are using NSKeyedArchiver and NSKeyedUnarchiver to wrap Dictionary into NSData. 5. Remove app from device to have clear start. 6. Tap "Save Yes" Log from console is saying: registered defaults: [a: 0] loaded: [a: 0] to be saved: [a: 1] loaded: [a: 1] /// Value has been saved and is readed correctly Expected Results: Dictionary stored in User Defaults should be stored correctly Actual Results: Key and value for Dictionary is not saved in NSUserDefaults Version: iOS 8 Notes: Configuration: iPhone 5, iOS 8, Xcode 6.0.1, Swift, OS X Mavericks 10.9.4 Attachments: 'iOS8-NSUserDefault-bug.zip' was successfully uploaded. I keep this in my dropbox account. If you want to test it you can download project from here: https://dl.dropboxusercontent.com/u/11493275/openradar/18403298.zip
Comments
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!