Objective-c protocol function

The role of Protocol:

1. Define a set of public interfaces (Public)

  @required: methods that must be implemented, all methods in @protocol are required to be implemented by default.

  @optional: optional implementation method (can not be implemented at all)

2. Delegate value transfer:

  It is a design pattern in itself, and it means to entrust others to do something.

  For example: to pass values ​​between two classes, class A calls the method of class B, class B encounters a problem in the execution process to notify class A, this time we need to use a delegate (Delegate).

  Another example: the transfer value between the controller (Controller) and the controller (Controller), jump from C1 to C2, and then return from C2 to C1, need to notify C1 to update the UI or do other things, then we will Use the delegate (Delegate) to pass the value.

Guess you like

Origin blog.csdn.net/qq_27740983/article/details/50176211