Title here
Summary here
The possible values for ServerState
are defined as constants. Swift automatically assigns successive integer values starting from 0.
By conforming to the CustomStringConvertible
protocol, values of ServerState
can be converted to String
.
If we have a value of type Int
, we cannot pass it directly to transition
without explicitly converting it to the enum type, providing compile-time type safety.
The transition
function emulates a state transition for a server; it takes the existing state and returns a new state.
Now that we have implemented a simple enum-based state machine in Swift, we can explore more advanced features of the language.