Considerations for the Agreement:
A, if a class adheres to an agreement, its subclasses also abide by the agreement. B, the protocol does not refer to any class, it is non-class (classless). Any class can comply with an agreement. C, by adding the protocol name in the angle brackets after the type name, you can check the consistency of the variables with the help of the compiler, as
Under
ID <Drawing> currentobject;
This tells the compiler that Currentobject will contain objects that comply with the Drawing protocol. If you assign a static type of currentobject to the
Like, this object does not comply with the Drawing protocol, and the compiler will give the warning.
Once again, if you assign an ID variable to Currentobject, this message will not be generated because the compiler does not know
Whether the object stored in the ID variable complies with the Drawing protocol. D, if the object that this variable holds adheres to multiple protocols, you can list multiple protocols, as follows:
ID <drawing, Drawing 1> currentobject; E, when defining an agreement, you can extend the definition of an existing protocol. The following protocols
@protocol drawing3d <Drawing>
Note The DRAWING3D protocol also uses the Drawing protocol. Therefore classes that employ the DRAWING3D protocol must implement this Protocol to list
method, and the method of Drawing protocol. F, the classification may also adopt an agreement, such as:
@interface fraction (stuff) <nscopying, nscoding>
Here, Fraction has a classification stuff, which uses the nscopying and nscoding protocols.
iOS Learning Summary (iv)