1. In general, when importing Objective C's header file, use #import to include the C + + header file with #include.
2. #import determine that a file can only be imported once, which allows you to avoid problems with recursive inclusion. < tags >
Therefore, the advantage of #import比起 #include is that it does not cause cross compilation.
#import && #class:
1. Import contains all of the information for this class, including entity variables and methods (. h files), and @class just tells the compiler that the name declared later is the name of the class, and how these classes are defined will be followed by you.
2. In the header file, it is generally only necessary to know the name of the referenced class. There is no need to know the internal entity variables and methods, so in the header file it is generally used @class to declare that the name is the name of the class. In the implementation class, you need to use #import to contain the referenced class's header file because it uses the internal entity variables and methods of the reference class.
Note: #import is to go through the header file of the referenced class, that is, to include the variables and methods in the. h file once, and only once, but not @class, so the latter is more efficient to compile.
3. In terms of compiling efficiency, if you have 100 header files that have #import the same head file, or these files are referenced in turn, such as A–>b, B–>c, c–>d such a reference relationship. When the first header file changes, all the classes that refer to it later need to be recompiled, and if you have a lot of classes, this will take a lot of time. But using @class is not.
4. If there is a cyclic dependency, such as: A–>b, b–>a such interdependence, if the use of #import to each other, then there will be a compilation error, if the use of @class in the two-class header files to each other, there will be no compilation errors occur.
Note: Practice has proved that a,b with each other #import no compilation errors occur. This is not true because the < tag > has explained that the file was only imported once #import.
Summarize:
1. If it is not C + +, try to use #import.
2. Can #import in the implementation file, not in the header file #import.
3. Can be in the header file in the @class+ implementation file #import, is not in the header file #import.
The above is a small set for you to introduce the development of iOS #import, #include和 @class difference analysis, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!