the difference between #import and #include in objective-c
Pre-compilation Directives
OBJECTIVE-C: #import: Supported by the GCC compiler
C,c++: #include
In Objective-c, #import is used as an improved version of the #include directive. In addition, #import determine that a file can only be imported once, which allows you to have no problem with recursive inclusion.
It's up to you to decide which one to use. In general, when importing the OBJECTIVE-C header file, use the #import, #include when the C header file is included.
The benefit of #import比起 # include is that it does not cause cross-compilation
second, @class is used to do the class reference
@class is to tell the compiler that there is such a class, as to what the definition of the class is.
@class is commonly used in header files to declare an instance variable of the class, and in M files it is necessary to use #import
As an example:
In the ClassA.h
#import ClassB.h equivalent to include the entire. h header file. If there are many. m files #import ClassA.h, then these files will #import ClassB.h add unnecessary #import and waste compilation time when compiling. In large software, it is important to reduce the include in. h files.
If just @class ClassB then there is no include ClassB.h. Only need to #import in the CLASSA.M file that requires ClassB ClassB.h
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;
Object-c syntax-header file Reference (@class/#import/#include)