wwayne / react-native-user-defaults

All you need is set and get
MIT License
58 stars 10 forks source link

fix JSON.parse error (can occur with shared NSUserDefaults) #4

Closed MacKentoch closed 8 years ago

MacKentoch commented 8 years ago

When NSUserDefaults is shared (via group) with a widget for instance it can lead to JSON.parse error when value stored by widget is a JS primitive: string or number.

Fix here userDefaults.get and userDefaults.set for

// in swift, your widget could store :
let userDefaults = NSUserDefaults(suiteName: "SUITE_NAME")
userDefaults?.setObject("a string for this key", forKey:"KEY_NAME")
userDefaults?.synchronize()

this fix insure string and number won't throw errors.