Essentially, my variable (playerErrors) is updated by a button push and then the view controller is segued to the next with data transferring. However, the variable\'s value (wh
It should work with something like this:
@IBAction func youErrorDeep(_ sender: Any){
playerErrors += 1
playerErrorsDeep += 1
print("deep \(playerErrors), \(playerErrorsDeep)")
self.performSegue(withIdentifier: "segueForYouErrorDeep", sender: self) //instead of "segueForYourErrorDeep" use the identifier for the correct segue
}
You would have to give each segue a unique identifier, but this way you can still use the storyboard to a certain extent.
This also ensures that the segue is executed after the operations.
If you're unsure how to give a segue an identifier, all you have to do is click on the segue graphic and under attributes set the identifier to an arbitrary string.
You aren't calling peformSegueWithIdentifier:sender
anywhere in your code, so I assume that you are triggering the segue directly from the action outlet in Interface Builder.
This won't work where you need to execute some code on the button press, since the segue may occur before the @IBAction
method executes.
You should remove the segue from the action outlet, create a segue from your View Controller object in Interface Builder, give this segue an identifier and the you can initiate it from your @IBAction
method using performSegueWithIdentifier:sender
.
Also, for readability and maintainability, I strongly suggest you create a class to store the player state and then you can just pass an instances of this class rather than 16 separate variables