Post

Replies

Boosts

Views

Activity

On/Off Button Title in updateUI()
I am working through the Getting Started with App Development and on Page 142 it has you write in the updateUI() function if else statement lightButton.setTitle("Off", for: .normal) and lightButton.setTitle("On", for: .normal). My app crashes every time after building it and running it. Image reference below. The app works perfectly fine before adding these two statements. import UIKit class ViewController: UIViewController { @IBOutlet var lightButton: UIButton! var lightOn = true fileprivate func updateUI() { if lightOn { view.backgroundColor = .white lightButton.setTitle("Off", for: .normal) } else { view.backgroundColor = .black lightButton.setTitle("On", for: .normal) } } @IBAction func buttonPressed(_ sender: Any) { lightOn.toggle() updateUI() } override func viewDidLoad() { super.viewDidLoad() updateUI() // Do any additional setup after loading the view. } } Getting this error at the end. libc++abi: terminating due to uncaught exception of type NSException (lldb)
5
0
392
Jul ’23