Taytee Taytee - 2 months ago 8
Swift Question

If (Bools = true) not executing -Swift

Attempting to execute a modal segue when multiple different Bool variables are all true (activated true through IBAction button push), however, nothing is happening- here is how they are all setup-

UIViewController {

// INITIAL TO CHECK WHICH BUTTONS HAVE BEEN PUSHED //
var 1Check = Bool()

// Checks //
@IBAction func 1(_ sender: AnyObject) {
1Check = true
}


and here is the execution-

viewDidLoad() {
super.viewDidLoad()
MoveOn()
}

func MoveOn(){
if (1Check == true && 2Check == true ...) {
self.performSegue(withIdentifier: "NewScreen", sender: nil)

}
}


what am I missing? Thanks!

Answer

The call to MoveOn() needs to be in a place where it will be called every time one of those checked values changes:

UIViewController {

    // INITIAL TO CHECK WHICH BUTTONS HAVE BEEN PUSHED //
    var 1Check = Bool()

    // Checks //
    @IBAction func 1(_ sender: AnyObject) {
        1Check = true
        MoveOn()
    }

    viewDidLoad() {
        super.viewDidLoad()
    }

    func MoveOn(){
        if (1Check == true && 2Check == true ...) {
            self.performSegue(withIdentifier: "NewScreen", sender: nil)

        }
    }
}
Comments