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