#include #import @class Explanation
#include
distinction #include <x.h> and #include" x.h " #include <x.h>: It is used to reference the header file that comes with the system, and the compiler will be in the
System files directory down to find the file .
#include "x.h": user-defined files are quoted in double quotes, and the compiler first
Look in the user directory, and then look in the installation directory, and finally in the system files.
when using#includebe careful to handle duplicate references (this is alsoOBJCin#includewith the#importthe difference)
For example:ClassAwith theClassBalso reference theClassC, do not do duplicate reference processing at the time ofCLASSDboth references inClassA,ClassBcompilation prompts you toClassCDuplicate-referenced error.
we can : #ifndef _classc_h#define _classc_h
#include "ClassC"
#endif This handles errors that do not have a duplicate reference at compile time (in objc
#import solved the problem, which is the difference between them) #import
#import Most features and #include is the same, but he dealt with the problem of repeated references, we do not have to refer to the file for repeated reference processing .
@class
mainly for declaring A class that tells the compiler that the name behind it is the name of a class, and that the definition implementation of this class is not known for the time being, and will tell you also because @class just declares a class, so in the following implementation file you need to go to #import This class, this time contains all the information of this referenced class.
In summary #include , #import with the @class the difference can be made to understand:
#includewith the#importwhen referencing a class, it contains all the information about the class including the variable method, but it will affect the efficiency of the compilation ..For example, there -A class is#importtheClassA, then at compile time this -A class will go to theClassAprocessing.Another exampleAwasBreferences,BwasCreferences,CwasDReferences.....at this point, ifAbe modified, then the back of theB,C,D .....need to be re-compiled.There is also a usage that can cause compilation errors in theClassAin#import ClassBin theClassBin#import ClassAThen there will be an unknown error at compile time.
so in general,InterfaceA class is referenced in the@class, it will use this class as a type, and in implementing thisInterfacefile, if you need to refer to the entity variables or methods of this class, you need toImport
this in @class the class declared in the.
The difference between IOS #include与 #import