Swift Protocol and Implementation
Protocols in Swift , define requirements that has to be implemented by a Class adopting or conforming to it. Protocols can be adopted by a Class , Structure or Enumeration , all of which can actually implement them based on the requirements. But, in one scenario you can't adopt protocol for Structure and Enumeration. Please go through the entire article for further understanding. Lets consider a simple example with Inheritance and Requirement (Protocol defines Requirements). Object Inheritance. Department Object is inherited by Administration , Finance and Human Resource Department. So all the departments will have inherited properties like departmentName and departmentId. Protocol. Protocol define the requirements. These requirements can be required or optional. requirements If you notice in the design listed below, you will notice two type's for requirements. 1) Required func dressCode(departmentType: Int ) -> UIColor func number...