iOS NSUserDefaults check if float key exists

ios, nsuserdefaults

Solution

A reliable way to see if a default has been set is:

if (![[NSUserDefaults standardUserDefaults] valueForKey:@"foo"]) { ... }

This works regardless of the data type.

Problem

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?

Original source

Related problems