@class
What is @class? How to use @class?
@class can simply refer to a class
@class Specific use:
Referencing a class in an. h file using @class
Use #import in. m files to include the. h file for this class
The difference between #import and @class
Import is a precompiled directive that copies the files in the "" to the location of the import, and the import has a feature that imports will be re-copied once the files in "" Have changed (update operation)
@class just tell the compiler that the name behind the @class is a class and will not do any copy operations
Note: Since @class simply tells the compiler that the name is a class, the compiler does not know what properties and methods are in the class, so the class needs to be import when using this class in. m.
What is an indirect copy
If all are in. h Import, if a copies B, B copies C, if C is modified, then both B and a need to be re-copied.
Because C modifies then B will be re-copied, and B re-copy after the equivalent of B has been modified, then a also need to re-copy. That is, if all copies are in. h, they will be re-copied as long as there are indirect relationships.
How to solve indirect copy problems using @class
If you use @class in. h and import in. m, then if a file changes, only the file that is directly related to the file will be re-copied.
So using @class in. h can improve compilation efficiency
How do I solve two-class mutual copy problems using @class? What is the principle of mutual copying?
1. If two classes are copied to each other, such as a copy B, b copy A, this will cause an error.
2. Workaround: Use @class in. h, import in. m
3. Principle:
Because if you use import in. h, then a copy B, b and copy a, it will form a dead loop if you use @class in. h, then no copy operation is done, and the import in. M only copies the corresponding file, and does not form a dead loop
Cyclic retain
What is a cyclic retain?
If a object is to have a B object and the B object has an A object, a loop is formed retain
How to solve the cyclic retain?
A: Do not let a retain B, b retain a so that one side do not do retain operation can
[email protected] and loop retain