Objective-c Knowledge Summary (4)

Source: Internet
Author: User

ARC (automatic reference counting) mechanism

Determine if the ARC mechanism

    • Retain release autorelease cannot be used in the ARC mechanism Retaincount
    • [Super Dealloc] cannot be used in the Dealloc method;

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.