Create a ticket agreement. The agreement stipulates whether the output will be left
1 #import <Foundation/Foundation.h>23@protocol buyticketsdelegate < Nsobject>45@required6 -(void) check; 7 8 @end
View Code
Create a proxy Agent compliance protocol
1 #import "Buytickets.h"2 @interfaceAgents:nsobject<buyticketsdelegate>3 4 @end5 6 7 @implementationAgents8 9- (void) check{TenNSLog (@"There are still tickets left ."); One } A - @end
View Code
Create a person class that contains a proxy object that adheres to the protocol
1 @interfacePerson:nsobject2 3@property (nonatomic, assign)ID<BuyticketsDelegate>Delegate;4 5- (void) Buy;6 7 @end8 9 Ten #import "Person.h" One @implementation Person A -- (void) buy{ - [_delegate check]; the } - - @end
View Code
In the main function, specify a proxy
1 intMainintargcConst Char*argv[]) {2 @autoreleasepool {3 4Person *person =[[Person alloc]init];5Agents *age =[[Agents alloc]init];6Person.Delegate=Age ;7 [person buy];8 9 Ten } One return 0; A}
View Code
A simple example of OC protocol and Proxy