Skip to content

Tag: RawRepresentable

RawRepresentable and associated values

RawRepresentable is a protocol in Swift standard library and enables converting from a custom type to raw value type and back. In this post we’ll be looking into how to implement RawRepresentable for enumeration containing an associated value. Conforming to RawRepresentable Implementing RawRepresentable requires three steps: firstly, choose RawValue type; secondly, implement initialiser where RawValue type is matched to one of the cases in the enumeration, and thirdly, rawValue getter where enumeration cases are converted into RawValue type. In the example we’ll be looking into enumeration representing scenes: home, levelSelection… Read more RawRepresentable and associated values