The following code is from the Stanford Swift lecture that Apple endorses:
@IBOutlet var cardButtons: [UIButton]!
@IBAction func touchCard(_ sender: UIButton) {
flipCount += 1
if let cardNumber = cardButtons.firstIndex(of: sender)
{
game.chooseCard(at: cardNumber)
updateViewFromModel()
}
}
func updateViewFromModel()
{
for index in cardButtons.indices {
var button = cardButtons[index]
var card = game.cards[index]
//Loop always iterates here <-- the problem
if card.isFaceUp
{
//button.setTitle(emoji( for: card), for: .normal)
button.backgroundColor = card.isMatched ? .lightGray : .orange
button.isEnabled = card.isMatched ? false : true
} else
{
//button.setTitle("", for: .normal)
button.backgroundColor = .orange
}
print("Apple should be ashamed of xcode 11")
}
}
The code never reaches the if-else statements. It exits the loop after the var card statement (using let produced the same result). It took me hours to identify this. This ran in xcode 10.