I am trying to pass the boolean value of UISwitch to another class using NSUserDefaults . For some reason, in a class that contains keys, if , which must be set to NSUserDefaults , cannot read switch declarations.
ViewController.swift
@IBOutlet var shrimpSwitch: UISwitch! @IBOutlet var nutSwitch: UISwitch! @IBOutlet var dairySwitch: UISwitch! let switchState = NSUserDefaults.standardUserDefaults() if shrimpSwitch.switch.on{ switchState.setBool(true, forKey: "shrimpSwitch") } else{ switchState.setBool(false, forKey: "shrimpSwitch") } if nutSwitch.on{ switchState.setBool(true, forKey: "nutSwitch") } else{ switchState.setBool(false, forKey: "nutSwitch") } if dairySwitch.on{ switchState.setBool(true, forKey: "dairySwitch") } else{ switchState.setBool(false, forKey: "dairySwitch") }
In the first statement of If (shrimpSwitch.on) he will say "Expected Declaration." I declare that all switches are wrong? Any help would be greatly appreciated. Thanks
xcode swift nsuserdefaults
Giancarlo manuel guerra salvรก
source share