I am struggling to figure out how to do an if statement with a bool saved to NSUserDefaults using Swift. I believe I know how to save the bool to NSUserDefaults but a confirmati
if NSUserDefaults.standardUserDefaults().boolForKey("onoroff") == true
The above code is only check wheather the value of the key is true or not.
or
if NSUserDefaults.standardUserDefaults().objectForKey("onoroff")
The above code check wheather the value of the key is true or not as well if there is no value for the key.(Means Nothing inserted in the UserDefault of "onoroff").
EDIT
if !NSUserDefaults.standardUserDefaults().objectForKey("onoroff")
{
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "onoroff")
}
else
{
NSUserDefaults.standardUserDefaults().setBool(false, forKey: "onoroff")
}