More haste less defaults (NSUserDefaults)

If you have an iOS app that relies on setting a user default, then don't be too hasty exiting the app when testing. For example, if you test for iCloud preference only on first opening, as suggested by Apple's documentation,

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"SubsequentLaunch"];

don't open the app once and then close immediately after the code for setting the notification for the app having been opened has been sent.

Why not? Because this approach will not provide enough time for the associated .plist file to be created and so it will look like the preference was never set, even though the NSUserDefault method was called to set the BOOL or value.


Endorse on Coderwall

Comments