Declaring a class that conforms to multiple protocols

Now, we will declare a class named Animal that conforms to both the previously defined AnimalProtocol and Equatable protocols. The latter is a fundamental type in Swift. In order to conform to the Equatable protocol, we must implement the == operator function for the Animal class to determine the equality of the instances after we declare the class. This way, we will be able to determine the equality of the instances of classes that implement the AnimalProtocol protocol. We can read the class declaration as "the Animal class implements both the AnimalProtocol and Equatable protocols." Take a look at the following code. The code file for the sample is included in the swift_3_oop_chapter_06_01 ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.