One, there are two different ways to import header files: Use quotation marks or use angle brackets, for example, #import <Cocoa/Cocoa.h> and #import "Tire.h". The statement with angle brackets is used to import the system header file, The quoted statement indicates that the imported header file is local to the project, and if you see the header file name enclosed in angle brackets, the header is read-only for your project because it belongs to the system. If the header file name is enclosed in quotation marks, then you (or someone else who participates in the project) can edit it.
Second, OBJECTIVE-C provides a way to reduce the impact of recompilation caused by dependencies. Dependency problems exist because the OBJECTIVE-C compiler needs some information to work. Sometimes, the compiler needs to know all the information about the class, such as its instance variable configuration, all the classes it inherits from, and so on. In some cases, the compiler simply needs to know the class name, without needing to know its whole meaning.
For example, when an object is composited, this composite uses pointers to objects. This works because all Objective-c objects are stored in dynamically allocated memory. The compiler just needs to know that this is a class. It then finds that the instance variable is the size of the pointer, and the size of the pointer does not change throughout the program.
Objective-c introduced the keyword @class to tell the compiler: "This is a class, so I just need to refer to it by pointers." "This way the compiler will" calm down ": it doesn't need to know more about the class, just understand that it is referenced by pointers.
A forward reference was created @class. is to tell the compiler: "Trust me, you'll know what this class is, but for now, you just need to know that," @class can be useful if you have a circular dependency. That Class A uses Class B, and Class B also uses Class A. If you try to get these two classes to refer to each other through a #import statement, a compilation error will occur. But if you use @class B in A.h and @class A in B.h, then these two classes can be referenced to each other.
Third, sometimes we import Engine.h in the file without importing the <COCOA/COCOA.H> We know that <cocoa/cocoa.h> has been imported into the Engine.h, so we don't need to import it ourselves again. However, if you want to add #import <cocoa/cocoa.h> to the file, this is possible because the #import command has enough intelligence that it does not repeatedly import its own files.
Four, in the learning process, we recognize the cross-file dependencies, in which the header file or source file needs to use the information in another header file. A duplicate import of files increases the number of compilations and also causes unnecessary duplication of compilation. The clever use of the @class command can reduce compilation time, @class tell the compiler to "trust me, you can finally learn the name of the class", which reduces the number of header files that have to be imported.
Reference: "Objective-c Basic Course"
"Reading Notes" ios-header file import [email protected] considerations