Declaring protocols

Now, it is time to code the protocols in Swift. We will code the following five protocols:

  • ComicCharacter
  • GameCharacter
  • Alien
  • Wizard
  • Knight

The following UML diagram shows the five protocols that we will code in Swift, with their required properties and methods included in the diagram. In this case, the diagram shows only protocols and we don't use any mark above the protocol name. However, in other diagrams in which we will mix protocols with classes, we will add procotol after the protocol name. UML diagrams have specifications for interfaces, but we will use our own mechanism to identify protocols:

Declaring protocols

The following lines show the ...

Get Swift 3 ObjectOriented Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.