I am learning Swift by Apple's books. I am stuck at this problem. I'm trying to connect button programmatically, but I receive this problem.
Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
Here is my code:
class ViewController: UIViewController {
@IBOutlet var toggle: UISwitch!
@IBOutlet var slider: UISlider!
@IBOutlet var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)
}
@IBAction func buttonTapped(_ sender: Any) {
print("Button was tapped!")
if toggle.isOn {
print("The switch is on")
} else {
print("The switch is off")
}
print("The slider is set to \(slider.value)")
}
/// not all ....