Where I can use Enums?

Hello everyone who can explain me why do we need enums in our code? I did not understand where we can use it I read few tutorials even watched videos but I mixed everything
can you bring any example where I can use Enumerations?
Thank you in advance

So one example which is use quite frequently is in games I make. I use enmus for game states. For example:

enum gameState {
    case preGame
    case inGame
    case postGame
}

It allows me to check gameStates during my game functions, like below:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    
    if currentGameState == gameState.preGame {
        startGame()
    }
        
    else if currentGameState == gameState.inGame {
        isFiring = true
    }
}
1 Like