iOS Learning Summary (iv)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.