There are times when we would like to describe the implementations (methods, properties, and other requirements) of a class without actually providing the implementation. For this, we would use protocols.
Protocols define a blueprint of methods, properties, and other requirements for a class or a structure. A class or a structure can then provide an implementation that conforms to those requirements. The class or structure that provides the implementation is said to conform to the protocol.
The syntax to define a protocol is very similar to how we define a class or a structure. The following example shows the syntax used to define a protocol:
protocol MyProtocol { //protocol definition here }
We state that a class or structure conforms to a particular protocol by placing the name of the protocol after the class or structure's name, separated by a colon. Here is an example of how we would state that a class conforms to the MyProtocol
protocol:
class myClass: MyProtocol...