Understand Protocols — iOS

Jay Mayu
3 min readJul 12, 2017

I’m not sure why many developers (even some senior developers) confuse Protocols with Object and Struct.

You can think of Protocols as a superclass with some rules. When you conform to that class you’ll have to simply obey those rules. In this case these rules can be methods and properties. Let’s look at an example so you’ll get a clear idea.

Let’s define our Protocol first.

Now you see the main difference between a Class and Protocol. You don’t implement your methods here in Protocol. It’s simply just defined.

Let’s create a Cat class now.

Now conform the Cat class to the Animal protocol as below

--

--