I can't seem to figure out how to have a function block repeated when a UIButton is pressed in swift. Here's what I have:
class CoinFlip: UIViewController {
@IBOutlet var resultLabel: UILabel!
var randomNumber = (Int(arc4random_uniform(2)))
@IBAction func tossButton(sender: UIButton) {
if randomNumber == 0 {
resultLabel.text = "Heads!"
}
else if randomNumber == 1 {
resultLabel.text = "Tails!"
}
}
}
When the button is pressed in the app, it picks a random number. If I hit it again, it displays the same number. What can I do so each time I hit the button it refreshes?
Aucun commentaire:
Enregistrer un commentaire