Enums
Enums create named constants with auto-incrementing integer values.
enum Color { Red, Green, Blue }print(Color.Red) // 0print(Color.Green) // 1print(Color.Blue) // 2Custom values
Section titled “Custom values”enum Status { Active = 1, Inactive = 0, Pending = 2 }
if (status == Status.Active) { print("active")}Auto-increment
Section titled “Auto-increment”Auto-increment continues from the last assigned value:
enum Level { Low = 10, Medium, High }print(Level.Medium) // 11print(Level.High) // 12Enums are maps
Section titled “Enums are maps”Enums are implemented as maps, so you can pass them around, iterate their keys, and use them anywhere a map is expected.