[IOS] ARC experience record

Source: Internet
Author: User

1. You do not need to write three keywords: retain, release, and autorelease;

2. An object will not be destroyed as long as it is pointed by the strong pointer until all the strong pointers pointing to it point to other places;

3. By default, all instance variables and local variables are of the strong type;

4. The weak type pointer does not hold the object. When the indicated object loses all the strong pointers pointing to it, the object is destroyed and the weak pointer automatically points to nil;

6. Remember:-fobjc-arc and-fno-objc-arc;

7. In addition to basic types such as int, float, and bool, most assigns can be replaced by weak;

8. Existing
Instance variable for _ weak property must be _ weak solution: @ Property indicates that weak should be declared as _ weak in the attribute list;

9,

    OSStatus status = SecItemCopyMatching((CFDictionaryRef) attributeQuery, (CFTypeRef *) &attributeResult); 

The changes are as follows:

    CFTypeRef attri = (__bridge CFTypeRef)attributeResult;    OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)attributeQuery, &attri);

10. dealloc only handles some necessary tasks, such as suspending an unfinished network request, deleting a registered proxy or notification. Release and [Super dealloc] are not required.

11. Use the @ autoreleasepool {} block to replace the NSAID utoreleasepool;

12. The attribute name is not developed in new mode;

13. nsallocateobject and nsdeallocateobject are not used

14,

_ Bridge

Simple assignment does not affect the retain count of objects on both sides.

_ Bridge_transfer

Release objects on the right after assigning values

_ Bridge_retained

The objects on the right are retained after the assignment.

15. iboutlet should be weak-type;

16. To call the core foundation function named create, copy, and retain, you must use cfbridgingrelease () to safely pass the value to arc;

17. To avoid self capture, the following code mode is recommended:

__weak id weakSelf = self; block = ^() { id strongSelf = weakSelf; if (strongSelf != nil) { // do stuff with strongSelf } }

18. Arc Singleton

+ (id)sharedInstance { static ClassName *sharedInstance; static dispatch_once_t done; dispatch_once(&done, ^{ sharedInstance = [[ClassName alloc] init]; }); return sharedInstance; } 


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.