MΓ³dulo 02 Β· Swift, One Level Deeper β LecciΓ³n 3 de 5 Β· ~15 min
Enums: A Fixed Set of Choices
A fixed set of choices
A PawWalk user is an owner or a walker. Not both, not "ownerr" with a typo, not some surprise third thing. When a value can only be one of a known, fixed set of choices, Swift gives you the enum (enumeration).
You declare the choices as cases. A value of the type is exactly one case: let role = UserRole.owner. And when Swift already knows the type, you can use the beloved dot shorthand: let role: UserRole = .owner.