10. Protocols
Protocols in Swift are similar to Interfaces in many other languages like Java.
Protocols are like 'standards,' 'guidelines,' or 'interfaces.' A real-life example of that could be the 'USB-C' interface. Think about your laptop, desktop, or phone having USB-C ports. See, the devices implementing these USB-C interfaces are all different, but they all have implemented a standard. The standard describes the physical properties of the interface to which a USB-C connector cable will get attached, how many channels for data communications and power will be there, and what functionalities the devices must implement to have this USB-C interface.
We will cover the very basics of protocols for Swift here. A general syntax of a protocol is:
protocol SomeProtocol{
//protocol definition goes here...
}Last updated
Was this helpful?