Protocol Conformance
As noted earlier, the syntax for protocol conformance looks exactly the same as the syntax you use to declare a class’s superclass, as seen in Chapter 15. This brings up a few questions:
-
What types can conform to protocols?
-
Can a type conform to multiple protocols?
-
Can a class have a superclass and still conform to protocols?
All types can conform to protocols. You made a structure (Department) conform to a protocol. Enums and classes can also conform to protocols. The syntax for declaring that an enum conforms to a protocol is exactly the same as it is for a struct: a colon and the protocol name follow the declaration of the type. (Classes can be a little more complicated. We will get to them in a moment.) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access