I have a switch and I want to have something like this:
override func viewDidLoad() {
super.viewDidLoad()
if name.text == "Jack"{
switch.on = false
}
}
But it's not working! How can I change the state of a switch when the view controller is loading?
To disable switch :
To change the switch state to
off
:To disable switch :
Objective C
Swift
UISwitch
has a propertyisOn
to turn the switch on and off. Also don't use the nameswitch
since this is a reserved keyword in Swift.