October 2017
Intermediate to advanced
210 pages
5h 32m
English
A protocol can require that the conforming types provide specific methods. These methods are defined within the protocol exactly as we define them within a class or structure, but without the curly brackets and method body. We can define that these methods are instance or type methods using the static keyword. Adding default values to the method's parameters is not allowed when defining the method within a protocol.
Let's add a method named getFullName() to the FullName protocol:
protocol FullName {
var firstName: String {get set}
var lastName: String {get set}
func getFullName() -> String
}
The fullName protocol now requires one method named getFullName() and two read-write properties named firstName and lastName.
Read now
Unlock full access