I. 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 <foundation/Foundation. h>
# Include <asl. h>
# Include <mach/mach. h>
# 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;
From andy Pan's column