1.
# Include is the keyword used to reference files in C, while # import is the keyword used to replace include in obj-C. # Import can ensure that the same file can be imported only once, thus avoiding the repeated reference problem that is easily caused by # include. That is, classa references classc and classb also references classc, when both classa and classb are referenced by classd, a duplicate reference error is reported.
2.
# Import "" And # import <>:# import "to find the file to be imported from the current working directory. If the file is not found in the system class library, # import <> directly searches for the file to be imported from the system library.
3.
# Import and @ class:
@ Class only tells the compiler that this name is a class name. You do not need to consider how this class is implemented. Introduction @ class is mainly used to solve the reference deadlock-if the two classes have a circular dependency, that is, a-> B, B-> A, if # import is used for mutual inclusion, A compilation error occurs:
Expected specifier-qualifier-list before 'A' or expected specifier-qualifier-list before 'B '.
In general. in the H file, you only need to know the class name, so use @ class, and in. in M files, you usually need to know the member variables of the class, that is, the method. Therefore, you must use # import to import the class files.
Why not use # import to import class files directly in the. h file, because if a large number of header files are imported, the compiler will spend a lot of time compiling.
# Import needs to be used in the. h file:
1/If there is an inheritance relationship, use # import. For example, if a inherits B, you need to import B in.
2. To use a class with category, use # import in the. h file to import the category of this class.