Use of the agent in OC, use of the OC agent
Generally, the following steps are required for proxy:
1. Develop an agreement. The protocol can be declared in. h of the delegate object, or in a separate. h. After the protocol is developed, the method that requires proxy objects is declared in the Protocol.
2. Set proxy properties. After the protocol is set, you need to set a proxy attribute for the delegate object. The proxy attribute is used to store the proxy object of the delegate object. The specific format is as follows:
@ Property (nonatomic, assign) id <*****> delegate; // ***** indicates the protocol name.
3. Specify the proxy object. Generally, in a proxy object, the proxy of the specified delegate object is itself. Example:
* **. Delegate = self; // proxy Object Name ***
4. The proxy object is subject to the commission agreement.
5. methods required to implement proxy objects in the delegate Protocol
6. Delegate the methods in the protocol for the proxy object to be executed at the right time. That is, call methods in the implemented protocol. The common format is as follows:
If ([self. delegate respondsToSelector: @ selector (method name)]) {
// If the proxy implements the method in the protocol, the proxy will execute this method.
[Self. delegate method];
}