Using protocols with enumerations
As we mentioned in the introduction to this chapter, we can use protocols with enumerations to enforce consistency across different enumerations. By conforming to a protocol, enumerations can define properties or methods that provide additional functionality while maintaining type safety. This is particularly useful when working with enumerations that need computed properties, default behaviors, or require interaction with other types in a structured way. If you are not familiar with enumerations, we look at them in Chapter 6, Enumerations.
Enumerations conform to protocols exactly like structures and classes do by using the colon at the end of the enumeration declaration and then adding the name of the protocol. Let’s look at an example of this.
protocol Describable {
    var description: String { get }
}
enum VehicleType: Describable {
    case car, bike
    var description: String {
        switch self {
        case .car:
     ...