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:

The following lines show the code for the ComicCharacter
protocol. The public
modifier followed by the protocol
keyword and the protocol name, ComicCharacter
, makes up the protocol declaration. As happens with class declarations, the protocol body is enclosed in curly brackets ({}
). The code file for the sample is included in the swift_3_oop_chapter_05_01
folder:
...