Now, we will create additional instances of the previous classes and call methods that specified their required arguments with protocol names instead of class names. We will understand what happens under the hood when we use protocols as types.
In the following code, the first two lines of code create two instances of the
AngryDog class named
merlin. Then, the code calls the two versions of the
drawSpeechBalloon method for
brian. The second call to this method passes
merlin as the
ComicCharacter argument because
merlin is an instance of
AngryDog, which is a class that implements the
var brian = AngryDog(nickName: "Brian") var merlin = AngryDog(nickName: "Merlin") ...