How to convert a non-ARC project into an arc

Source: Internet
Author: User

Xcode comes with an auto-convert feature, but it's only suitable for smaller projects and is not suitable for large projects, so I'm here for full manual conversions.

1. Change the project compilation environment to ARC

Change the red circle from No to Yes

If your current project does not support arc technology, you can convert your project through an automatic conversion tool (tool in Edit>refactor>convertto Objective-carc), This tool automatically converts the points that are manually managed in all projects into the appropriate automated way (such as removing retain, release, etc.). This tool will convert all the files in the project. Of course you can convert individual files.

2. The following functions: Dealloc,retain,release,retaincount,autorelease. Prohibit any form of invocation and implementation (Dealloc may be implemented)

Erase or annotate all these memory-management things

3. NSAutoreleasePool cannot be used. You can consider direct comments

As an alternative, @autoreleasepool is introduced and you can use this more efficient keyword.

4. Do bridging conversion times wrong, replace with Xcode hint

Some rules of 5.ARC syntax

5.1. Retain, release, retain, Autorelease are not available in the code

5.2. Do not overload the Dealloc (the function can be overloaded if it is disposed of outside the object's memory, but cannot be called [Super Dealloc])

5.3. Cannot use Nsallocateobject, Nsdeallocateobject

5.4. Object pointers cannot be used in C struct bodies

Between 5.5.id and void * If cast requires a specific method (__bridge keyword)

5.6. Cannot use NSAutoreleasePool, but need @autoreleasepool block

5.7. The name of the property that cannot be started with "new" (if used there will be a compile error below "Properties ' s synthesized getter Followscocoa naming convention for returning ' owned ' Objects ")

6. Third-party package issues, third-party framework issues

Many third-party frameworks may be referenced in our project.

Most of them use a few macros to make the code adapt to both arc and non-arc (with # if __has_feature (OBJC_ARC)). If you have a small amount of code, consider rewriting yourself

You can manually change the third-party framework to arc yourself by following the steps above.

If it is a large frame, you can take this framework to keep the non-arc environment intact and continue to use it.

1, select the targets in the project, select the target you want to manipulate,

2, choose Build phases, in which Complie sources select the file that needs arc double-click, and enter in the input box:-FOBJC-ARC, if not arc input:-fno-objc-arc

How to convert a non-ARC project into an arc

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.