Simple state machine in Swift