Now, we will declare a class named Animal
that conforms to both the previously defined AnimalProtocol
protocol and the Equatable
protocol. 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 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:
public class Animal: AnimalProtocol, Equatable {
public let name: String
public var danceCharacters: String {
get {
return String()
}
}
public var spelledSound1: String {
get {
return String()
}
}
public var spelledSound2: String...