I want to check if a float stored in NSUserDefaults is pre-existing. The Apple documentation suggests that it floatForKey will return 0 if the key does not exist.
How do I correctly tell the difference between a stored 0 and a non-existent key?
A reliable way to see if a default has been set is:
if (![[NSUserDefaults standardUserDefaults] valueForKey:@"foo"]) { ... }
This works regardless of the data type.
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