Don't use min and max for this.
For instance, create a func to test validity:
Code Block | func isValidNumberOfPlayers(_ nb: Int) -> Bool { |
| return nb > 0 && nb <= 10 |
| } |
Then, when you create or read the list of players, for instance in an array with their names:
Code Block | var players: [String] = [] // You populate the array somewhere |
In the func where you declare the players, check the value, call
Code Block | if !isValidNumberOfPlayers(players.count) { |
| print("number of players is not correct") |
| // And do whatever you need to do |
| } |
If you want to give a more precise test result, you could do this:
Code Block | enum PlayersCheckState { |
| case ok |
| case null |
| case tooMany |
| } |
|
| func isValidNumberOfPlayers(_ nb: Int) -> PlayersCheckState { |
| switch nb { |
| case ...0 : return .null |
| case 1...10: return .ok |
| default : return .tooMany |
| } |
| } |
|
Then call
Code Block | switch isValidNumberOfPlayers(playersCount) { |
| case .null : print("No player") |
| case .tooMany: print("too many players") |
| case .ok: break // do whatever you need to do here |
| } |