Protocol protocol:
The protocol is similar to the interface in C #
L used to declare the method
L if a class complies with an agreement, then it has all the statements of the agreement.
L can comply with multiple protocols
As long as the parent adheres to a protocol, the subclass adheres to that protocol.
Comply with the agreement <,>
Inheritance by:
1. Protocol Definition
@protocol protocol Name
@required//Require implementation, do not implement will issue a warning
-(void) test;
@optional//Do not need to implement
-(void) test2;
@end
2. How to comply with the agreement
1> Class Compliance Agreement
@interface Class Name: Parent class < protocol name,......>
Base agreement: Any agreement is subject to that agreement <NSObject>
L A protocol that complies with another agreement can have all the method declarations of this Agreement
2> Protocol Compliance Agreement
@protocol Child protocol name < Parent protocol,........>//Much like inheritance in a class but not inheritance
Limit the object type when you top a variable and follow a protocol
nsobject< protocol name > *obj = Class of Compliance protocol
Requires Obj5, the saved object must obey Myprotocol3, and inherit the person
Person<myprotocol3> *person;
Protocol protocol Use