Differences between # import and # include in objective-C

Source: Internet
Author: User

Differences between # import and # include in objective-C




Pre-compiled commands
Objective-C: # Import
C, C ++: # include
# Import supported by the GCC compiler

In objective-C, # import is used as an improved version of the # include command. In addition, # import determines that a file can only be imported once, so that you will not encounter problems in recursive inclusion.

It is up to you to decide which one to use. Generally, # import is used when the objective-C header file is imported, and # include is used when the C header file is included. For example:

# Import

# Include
# Include


# Compared with # include, import does not cause cross-compilation.

2. @ class is used for class reference
@ Class is to tell the compiler that there is such a class. What is the definition of the class?

@ Class is generally used when the header file needs to declare an instance variable of this class. In the M file, you still need to use # Import



For example:
In classa. h
# Import classb. H is equivalent to # include the entire. h header file. If there are many. m Files # import classa. H, these files will also # import classb. h added unnecessary # import during compilation, wasting Compilation Time. In large software, it is very important to reduce the include in. H files.

If
Only @ Class classb does not include classb. h. You only need to # import classb. h In the classa. M file that requires classb

So when can I use @ class?
If you only need to declare a classb pointer in classa. H, you can declare it in classa. h.
@ Classb
...
Classb * pointer;

Differences between # import and # include in objective-C

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.