Now, we will declare a class that specifies that it conforms to the ComicCharacter
protocol in its declaration in the Playground. Instead of specifying a superclass, the class declaration includes the name of the previously declared ComicCharacter
protocol after the class name (AngryDog
) and the colon (:
). We can read the class declaration as "the AngryDog
class conforms to the ComicCharacter
protocol."
However, the class doesn't implement any of the required properties and methods specified in the protocol, so it doesn't really conform to the ComicCharacter
protocol, as shown in the following:
public class AngryDog: ComicCharacter { }
The Playground execution will fail because the AngryDog
class doesn't conform to the ComicCharacter
protocol, so the Swift compiler generates the following errors and notes:
error: type 'AngryDog' does not conform to protocol 'ComicCharacter' public class AngryDog: ComicCharacter { ^ note: protocol requires...