O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. What types can conform to protocols?

  2. Can a type conform to multiple protocols?

  3. 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.) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required