A brief introduction to the use of agent design patterns in swift and the value of closures
First, the agent mode
The agent simply means to let others help themselves to do something that is not or inconvenient to do.
The following steps are implemented for the agent:
1. Write a protocol, define the proxy method, is what needs to be done
2. Two objects (a, B) assuming B is the agent of a
3.A requires an attribute delegate
4.B comply with A's agreement, set agent Relationship a.delegate = B
5.B Implementation Agent Method
6.A Trigger Agent Event
As follows: Declaration protocol
Agent Properties
Comply with the agreement
Set up agent relationships
Implementing Proxy methods
Triggering agent Events
The above is the process of the agent, but the declaration of the above agreement, it must be implemented, and the OC inside similar @optional effect can be so written
Second, the closure of the simple practical and transfer value
1. Use Typealias to alias closures
2. Defining attributes
3. If not Typealias can write directly
4. Call closure, pass parameters
5. Implement closure, receive parameters
The above is the closure of the value of the packet, and the implementation of the OC basically the same.