October 2017
Intermediate to advanced
210 pages
5h 32m
English
Protocols can inherit requirements from one or more additional protocols and then add additional requirements. The following code shows the syntax for protocol inheritance:
protocol ProtocolThree: ProtocolOne, ProtocolTwo {
// Add requirements here
}
The syntax for protocol inheritance is very similar to class inheritance in Swift, except that we are able to inherit from more than one protocol. Let's see how protocol inheritance works. We will use the FullName protocol that we defined earlier and create a new protocol named Person:
protocol Person: FullName {
var age: Int {get set}
}
Now, when we create a type that conforms to the Person protocol, we must implement the requirements defined in the Person protocol, as ...
Read now
Unlock full access