# Include, # import, @ class differences

Source: Internet
Author: User

# Include <>: Used to reference a system file. The compiler searches for the file in the system file directory. # Include "xx. h": Used to reference User-Defined files. The Compiler first searches in the user directory, then installs the directory, and finally searches in the system directory. Note: Pay attention to repeated references when using include: class A and class B both reference class C. If class D References class A and class B, it will report an error of repeated references. # The import function is basically the same as the include function, but it avoids repeated references. So we basically use import in OC. @ Class tells the compiler that this class exists, but you do not need to tell the compiler how the class is implemented. if. the m file uses this class. m file summary import this class. In this case, why not import data directly in the header file? For example, class A references class B and class B references class C ...., class A, B, C... the header file has imported A lot of files, so if A is imported, the compiler needs to compile A large number of files and the Compilation Time will increase. Is @ class used in header files? Of course not. Sometimes # import is required. When should I use it? (1) If there is an inheritance relationship, use # import. For example, if B is A subclass of A, use # import when declaring A in B; (2) in addition, if A circular dependency such as A-> B, B-> A is mutually dependent, if # import is used in the header files of the two files to declare each other, then there will be a header file recycling error, then the @ class declaration in the header file will not make an error; (3) when there is a custom proxy, if you want to declare a proxy in the header file, for example, if @ interface SecondViewController: UIViewController is used when # import is not applied, an error occurs. Note that XXXXDelegate is custom.

Related Article

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.