Communication between two classes is often required in iOS development. For example, when a view data is modified, it is necessary to do something bad on the View Controller, in this case, you need to use a proxy. Generally, the proxy works with the protocol.
When defining a protocol, you can use @ required and @ optional to configure the methods that must be implemented and the methods that can be selected to comply with this Protocol.
For example:
Class A events need to notify Class B, and Class B becomes the proxy of Class.
Write a protocol in Class
@ Protocol xxdelegate <nsobject> @ optional-(void) function_name :() Class A @ Interface Class A @ property (nonatomic, weak) ID <xxdelegate> delegate @ end
Call in event
If ([self. Delegate respondtoselector: @ selector (function_name :)]) {[self. Delegate function_name: Self];}
Declare <xxdelegate> in Class B
Implement function_name
Dark Horse programmer-4. Proxy (delegate)