IOS-how to convert a non-ARC project into an ARC project (in practice), ios-arc

Source: Internet
Author: User

IOS-how to convert a non-ARC project into an ARC project (in practice), ios-arc
1. foreword because the company has a foreign food and beverage system, it has been programming for 3-4 years and has used non-ARC before. By this year, the first batch of iterative developers have long been absent, many memory leaks have been found, and the system does not automatically release the released memory. Once the app is used for a long time, the memory is not released, and the app crashes. It involves a lot of things and is extremely complicated. So I have the intention to completely convert this project into an arc project. After one week of conversion and one week of testing, the non-arc project was successfully converted to the arc project. Because it is rare to find companies that convert large and old apps to arc, there is very little information on the Internet. After this attempt, I have proved that it is feasible. Now I will summarize some of my problems in my blog. After all, ARC is the future of objc. Xcode comes with an automatic conversion function, but it is only suitable for small projects. It is not suitable for large projects. Therefore, I want to manually convert all of them here. 2. Change the project compilation environment to arc.

Change the red circle from No to Yes

 

 

If your current project does not support the ARC technology, you can use an automatic conversion tool to convert your project (the tool is in Edit> Refactor> convertize Objective-c arc ), this tool automatically converts all vertices that manually manage the memory in the project into appropriate automatic methods (such as removing retain and release ). This tool converts all files in the project. Of course, you can convert a single file. 3. The following functions: dealloc, retain, release, retainCount, and autorelease. Disable calling and implementation in any form (dealloc may be implemented)

Delete or comment out all the memory management items

4. nyothoreleasepool cannot be used. You can consider directly commenting

As an alternative, @ autoreleasepool is introduced. You can use this keyword with higher efficiency.

 

5. If an error is reported during bridging, use the xcode prompt to replace it.

 

6. ARC syntax rules

. Retain, release, retain, and autorelease cannot be used in the code.

. Do not reload dealloc (this function can be reloaded if it is to release processing other than the object memory, but cannot call [super dealloc])

. NSAllocateObject and NSDeallocateObject cannot be used

. Object pointers cannot be used in the C struct

6.5.5.if cast between ID and void * requires a specific method (_ bridge keyword)

6. You cannot use the nfutoreleasepool, but you need the @ autoreleasepool block.

. Attribute names starting with "new" cannot be used (if the following compilation error occurs, "Property's synthesized getter follows Cocoa naming convention for returning 'owned 'objects ")

 

7. Problems with third-party packages and third-party frameworks many third-party frameworks may be referenced in our project. Most of them use some macros to make the code adapt to both arc and non-arc (determined by # if _ has_feature (objc_arc ). If the amount of code is small, you can rewrite it yourself. You can manually rename a third-party framework yourself as follows. If it is a large framework, you can mark this framework to keep its non-arc environment unchanged and continue to use it. 1. select Targets in the project and select the Target you want to operate on,
2. Select Build Phases. In Complie Sources, double-click the file to which the ARC is required, and enter-fobjc-arc in the input box. If no ARC is required, enter: -fno-objc-arc Author: Clear Saup
Source: http://www.cnblogs.com/qingche/
The copyright of this article is shared by the author and the blog. You are welcome to repost it, but you must keep this statement and provide a connection to the original article on the article page.

 


How to mix ARC and non-ARC

Answer

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.