///
- Swift
- UIKit
- MVVM
dealTapped function
@IBAction func dealTapped(_ sender: Any) {
// Randomize some numbers
let leftNumber = Int.random(in: 2...14)
let rightNumber = Int.random(in: 2...14)
// Update the image views
leftImageView.image = UIImage(named: "card\(leftNumber)")
rightImageView.image = UIImage(named: "card\(rightNumber)")
// Compare the random numbers
if leftNumber > rightNumber {
// Left side wins
leftScore += 1
leftScoreLabel.text = String(leftScore)
}
else if leftNumber < rightNumber {
// Right side wins
rightScore += 1
rightScoreLabel.text = String(rightScore)
}
else {
// Tie
}
}
- iOS 14.2
- Xcode 12.0
- Swift 5.3
Just open project and run 🚀