Hello, I hope everyone is healthy!
I know it might sound stupid, but is it possible to pass an enum case with associated value "anonymously", i.e. to pass the case without any associated value provided?
enum Sport {
case football(team1: [String], team2: [String])
case basketball(team1: [String], team2: [String])
case tennis(player1: String, player2: String)
var numberOfPlayers: Int {
switch self {
case .football(_, _): return 11
case .basketball(_, _): return 5
case .tennis(_, _): return 1
}
}
// example function
func gameDetails(_ game: Sport) {
print("There are \(game.numberOfPlayers) player(s) per side."
}
// call the function
gameDetails(Sport.tennis(player1: "Nadal", player2: "Federer")) // Works. Prints "There are 1 player(s) per side."
gameDetails(Sport.tennis(_, _)) // Doesn't work
as seen in the switch/case statement in the computed property, the cases doesn't require values provided. I need this logic to apply to an enum case as a method parameter.
Any ideas how?