jeudi 26 janvier 2017

Access to value of the variable in if statement

I need to access the value of a variable in a if statement, this is my code:

var codeError : Int?

@IBAction func mySwitch(_ sender: UISwitch) {
     if sender.isOn {
        codeError = 1
     } else {
        codeError = 2
     }
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    print(codeError!)

}

But, I need to print(codeError!) print 1 or 2.

How do I achieve this? đŸ€”

Aucun commentaire:

Enregistrer un commentaire