extensionPlayer {
mutatingfuncupdateScore(_newScore: Int) {
history.append(newScore)
ifhighScore < newScore {
print("\(newScore)! A new high score for \(name)! 🎉")
highScore = newScore
}
}
}
player.updateScore(50)
// Prints "50! A new high score for Tomas! 🎉"// player.highScore == 50
ifletbestPlayer =players.highestScoringPlayer() {
recordHolder ="""
The record holder is \(bestPlayer.name),\
with a high score of \(bestPlayer.highScore)!
"""
}else {
recordHolder ="No games have been played yet."
}
print(recordHolder)
// The record holder is Erin, with a high score of 271!lethighestScore =players.highestScoringPlayer()?.highScore ?? 0// highestScore == 271