December 2018
Intermediate to advanced
414 pages
10h 19m
English
You define protocols with the protocol keyword:
protocol BasicProtocol {}
The same way classes can inherit from each other, a protocol can inherit from another as well. The syntax is the same as the one for classes:
protocol ComplexProtocol: BasicProtocol {}
Classes and structures can adopt protocols and a single type can conform to multiple protocols, as in the example:
class MyClass: MySuperClass, BasicProtocol, AnotherProtocol {}struct MyStruct: AnotherProtocol {}
Read now
Unlock full access