| Start |
|---|
| Optional and required methods By default, all the methods declared in a protocol are required. This means that any class that conforms to this protocol must implement those methods. It is also possible to declare optional methods. These method can be implemented only if needed. You mark optional methods with the In this case, only The This last example defines a protocol with two optional methods and two required methods. |
Checking existance of optional method implementations |
| Basic Protocol Definition Defining a new protocol: |
| Conforming to Protocols The following syntax indicate that a class adopts a protocol, using angle brackets. This means that any instance of NewClass will respond to methods declared in its interface but also it will provide an implementation for all the required methods of It is also possible for a class to conform to multiple protocols, by separating them with comma. Like when conforming to a single protocol, the class must implement each required method of each protocols, and each optional method you choose to implement. |
| Forward Declarations It's possible to declare protocol name without methods: use it your code (class definition, etc): and later define protocol's method somewhere in your code: It's useful when you don't need to know protocols details until you import that file with protocol definition. So, your class header file stays clear and contains details of the class only. |
| Check conforms Protocol Returns a Boolean indicating if the class conform the protocol:
|
Read Article
https://develop.horje.com/learn/1434/reference