1.

Explain Protocol Vs Class in ios Swift.

Answer»
  • A protocol, in its most basic form, explains what an UNKNOWN sort of object can accomplish. It has TWO or three different sorts of properties, as well as procedures. Protocol NEVER INCLUDES anything inside the methods, nor does it provide actual storage for the properties. You can build extensions to your protocols that give default implementations of the methods in a more advanced form. However, you are still unable to provide storage for properties.
extension Car : CustomStringConvertible { var description : String { get { return "Car: \(colour)" } }}
  • Classes are tangible objects. They are not needed to embrace protocols, which means they do not have to implement the required attributes and methods. Classes can be used to generate objects, whereas protocols are simply typed declarations. Consider protocols to be abstract definitions, whereas classes and structs are actual objects that can be created. An example of a class is given below:
class Car { var colour: String}


Discussion

No Comment Found