Member-only story
How to check if UserDefaults object is Empty
This will be a guide to check if UserDefaults has been set.
You will want to use this to make sure a value is not nil before you use it.
Here is a simple example in a ViewController class.
- Create a constant to interact with the
UserDefaults
- Create an
if
statement to check if the object does not exist. - If the object does not exist, then set a default option. In the gist above, I set it to dark.
There is no need to set the default option if the default object does exist because it has been set before.