协议:
protocol ExampleProtocol {
var simpleDescription: String { get }
mutating func adjust() }
遵循协议的类:
class SimpleClass: ExampleProtocol {
var simpleDescription: String = "A very simple class."
var oneProperty: Int = 20
func adjust() {
simpleDescription += " Now 100% adjusted."
}
}
当没有实现协议中的方法时就会出现“does not conform to protocol”的错误提示