in tutorials/tutorial4-completed/TicTacToe/TicTacToe/TicTacToeViewController.swift [55:74]
func announce(winner: PlayerType?, withCompletionHandler handler: @escaping () -> ()) {
let winnerString: String = {
if let winner = winner {
switch winner {
case .player1:
return "\(player1Name) Won!"
case .player2:
return "\(player2Name) Won!"
}
} else {
return "It's a Tie"
}
}()
let alert = UIAlertController(title: winnerString, message: nil, preferredStyle: .alert)
let closeAction = UIAlertAction(title: "Close Game", style: UIAlertActionStyle.default) { _ in
handler()
}
alert.addAction(closeAction)
present(alert, animated: true, completion: nil)
}