1. Definition of the Agreement
@protocol Agreement name <NSObject>
Method List ...
@end
2. How to comply with an agreement
1> Class Compliance Agreement
@interface Class Name: Parent class name < protocol name 1, protocol name 2>
@end
2> Protocol Compliance Agreement
@protocol protocol Name < Protocol 1, protocol name 2>
@end
3. Keywords for method declarations in the agreement
1> @required (default)
Requires the implementation method, if not implemented, there will be a warning
2> @optional
No implementation method required
4. When defining a variable, limit the object that this variable holds to a protocol
Class name < protocol name > * variable name;
ID < protocol name > variable name;
If the corresponding protocol is not followed, the compiler warns
5. Attributes declared in the @property can also be used as a limitation of compliance with the agreement
@property (Nonatomic, Strong) class name < protocol name > * attribute name;
@property (nonatomic, strong) id< protocol name > attribute name;
6. The agreement can be defined in a separate. h file, or in a class
1> If this protocol is used only in a class, the protocol should be defined in that class
2> If this protocol is used in many classes, it should be defined in a separate. h file
7. Classifications can be defined in separate. h and. m files and can also be defined in the original class
1> generally, it is defined in a separate file, because the function of classification is to extend the method without changing the original class.
2> defined in the original classification, only requires to be able to understand the grammar
Dark Horse Programmer----protocol-protocol