How to convert a non-ARC project to an ARC project

Source: Internet
Author: User

How to convert a non-ARC project to an ARC project

How to convert a non-ARC project to an ARC project

Xcode comes with an automatic conversion function, but it is only suitable for small projects. It is not suitable for large projects. Therefore, manual conversion is required for large projects.

1. 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> convertify Objective-CARC ), 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.

2. These 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

3. You cannot use the nyothoreleasepool. You can consider directly commenting

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

4. if an error is reported during bridging, use the xcode prompt to replace it.

5. ARC syntax rules

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

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

. NSAllocateObject and NSDeallocateObject cannot be used

. Object pointers cannot be used in the C struct

5.5.5.id and void * If cast requires a specific method (_ bridge keyword)

. NSAID utoreleasepool cannot be used, but @ autoreleasepool is required.

. Attribute names starting with "new" cannot be used (if the following compilation error occurs, "Property's synthesized getter followsCocoa 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 change a third-party framework to ARC by following the steps above.

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

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.