When the user logs in to my application, I download a token from my JSON server and store it in NSUserDefaults, as such:
[[NSUserDefaults standardUserDefaults] setValue:token forKey:TOKEN];
When the user logs out in a subsequent page, I call this method and return back to the login screen:
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:TOKEN];
(and before that I called [[NSUserDefaults standardUserDefaults] removeObjectForKey:TOKEN];)
It doesn't matter how I try to delete this user defaults, whenever I load up my app, it always shows me the full token and not an empty string nor a null value.
When reading around, apparently it has something to do with read write cycles? But even if i leave it for a while, the key still remains. Is this a simulator problem?
Whatever the cause, how do i get around this?
It's the simulator problem of caching the memory first. It only happens in xcode and should not happen on a device.
Do you call
[[NSUserDefaults standardUserDefaults] synchronize];
after the key was deleted? Maybe you are not persisting the changes into the database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With