Instancetype, ID, nsobject contact and Difference

Source: Internet
Author: User

1, ID and instancetype can omit the specific type, improve the universality of the code. and NSObject * Does not have this function.

2. Instancetype can only be used for the return type of the method, and the ID use is similar to NSObject *.

3. Instancetype will tell the compiler the current type, which is similar to NSObject *, but the ID is untyped for the compiler, and calling any method will not give an error.

4, for the Init method, ID and instancetype are no different. Because the compiler will optimize the ID to instancetype. When the type that is explicitly returned is the current class, instancetype can be used to avoid the compiler error condition that the ID brings.

5, NSObject * and ID are only included with one class Isa. But NSObject contains more definitions of the methods.

6, Instancetype should be the ID and NSObject * Two deficiencies of a supplement.

Instancetype, ID, nsobject contact and Difference

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.