In a simple memory game I have a struct that defines the two cards that are tapped and returns in mutating functions the integers firstFlippedCard and secondFlippedCard.
If these do not match by another property, I want both cards to 'flip back'. I made a transition function for this - however, I can only make the last tapped button to switch back using the following logic:
@IBAction func cardsPress(_ sender: UIButton) {
flip(sender: sender)
if cardBrain.checkFirstCard(card: sender.tag - 1) == true {
//stay flipped
} else if cardBrain.checkForMatch(card: sender.tag - 1).match == true {
//stay flipped
} else {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
self.backFlip(sender: sender)
})
}
}
Note that multiple UIButtons are linked to cardsPress. How can I make them both flip back instead of only the sender?