Delegate:
1 use of proxy design patterns we need to understand the three elements first.
* Principal: The person who entrusted others to perform certain operations (object)
* Agent: The person (object) who performs certain operations on the delegated area
* Protocol: (protocol) The client needs the action of the agent
The > protocol is a set of criteria (a stack of method declarations), only. h files. The definition of the agreement begins with the @protocol and ends with the @end.
The methods in the > protocol must be implemented by default, @required. Keyword @optional adornment method is optional, class implementation can not be implemented.
2 Design steps for delegate
Step 1: The client formulates a set of agreements (in the. h file of the principal party), which declares the method that the principal needs to execute by the agent (only method declarations)
Step 2: The principal declares a delegate property (assign adornment) that stores the proxy object
@property (strong,nonatomic) id< protocol name >delegate
Step 3: The agent needs to follow the protocol and implement the methods in the Protocol
Step 4: Set the agent as the delegate's agent (to store the proxy object to the delegate property of the delegate object)
Step 5: The client notifies the proxy object at the appropriate time to perform the appropriate action
An agent for iOS common design patterns and mechanisms