The protocol concept, which is analogous to an interface from Java, is common in the Swift programming language. A protocol outlines the necessary qualities, procedures, and specifications for a certain task.
The protocol can be thought of in its most basic form as an interface that describes some operations and characteristics. Instead of describing the implementation, the protocol is only described in terms of its attributes or basic procedures. Enumerations, functions, and classes can be defined to implement properties and methods.
After the names of the structure, enumeration, or class types, protocols are declared. It is possible to make both, a single, and many protocol declarations. Commas separate multiple protocols.
A protocol can be defined in a manner that is very similar to classes, enumerations, and structures:
// protocol definition goes here
We can define multiple protocols, which are separated by commas:
Class SomeClass: SomeSuperclass, Firstprotocol, Secondprotocol
// Structure definition goes here
Note: Commonly asked Swift interview questions.