Hello I am trying to pass back a variable that has the level number. After the user clears the round below is called
if enemyHP <= 0.0{
level = level + 1
battle(winPlayer:true)
}
then function battle is called
let alert = UIAlertController(title: "finished!", message: finishedMessage, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title:"Go Back",style:.default,handler:{action in
self.dismiss(animated: true, completion: nil)}))
self.present(alert,animated: true,completion: nil)
}
I am trying to display the level number in the previous view controller so I need the variable level to go be passed back. What is the best way for this? I have used segues and it doesn't work with the alert.
Delegate
protocol DataSentDelegate {
func Back(data: Int)
}
I used
delegate?.Back(data: level)
In the previous ViewController I added
func Back(data: Int){
new = data
}
print(new)
It doesn't appear.