ARC (automatic reference counting) mechanism
Determine if the ARC mechanism
Object release under Arc is judged by: The object does not have a strong pointer pointing
pointers By default are strong pointers , such as the objects we create are the default strong pointers
Person *P1 = [[Person alloc] init];
__strong modifier, this pointer is a strong pointer, can also not write
The __weak-modified pointer is a weak pointer
Circular reference issues under ARC
When two objects are owned by each other, if they are defined with strong, then it will cause the problem of circular reference, the two sides are strong pointers to each other, cannot be released
The way to solve this problem is to define one of the weak as a perfect solution to the problem.
Arc under Set method memory @property parameter
The @property in Arc
Strong: For OC objects, equivalent to retain in MRC
Weak: Used for OC objects, equivalent to assign in MRC (proxies generally weak,ui control with weak)
Assign: For basic data types, like the Assign in MRC
Copy: Generally used for nsstring, as in the MRC copy
ARC Note:
__weak person *p=[[Person alloc] init]; //
How to make an ARC project compatible with non-ARC classes
Make programs compatible with ARC and non-arc parts
- Change to non-ARC-FNO-OBJC-ARC
- Transformed into an arc,-f-objc-arc.
Where to add compiler flag-fno-objc-arc such as
Convert MRC to ARC (not recommended, try to do a backup)
Category (category)
Usage precautions for classification:
---------> cannot declare an instance variable in a categorical declaration
---------> cannot define instance variables and cannot use @property
---------> in the Classification method, you can access the instance variables in the class
---------> methods that have the same name as the class in the taxonomy Methods in the time Division class with priority access
When there is a method of the same name in more than one category, this time, the method of the same name that was executed in the last compiled category
Classification of the > Original class
Final compilation of categories > Other classifications
Classification (category) informal agreement
Informal agreements are classes (classifications) that are created for subclasses in the NSObject class or foundation framework, that is, adding methods to them, called informal protocols
The concept of the extension of a class
Extended categories are also known as extensions (extendsion)
Extension is a special case of category its name is anonymous (empty), and the newly added method must be implemented. (category does not have this restriction)
// This is typically used in. m files as private methods and member variables @interface Student () { // can add member variable }// Add method @end
Objective-c Knowledge Summary (4)