Enable and disable ios arc and non-arc

Source: Internet
Author: User

There are two ways to convert non-ARC Code to ARC Code:
1. Use Xcode's automatic conversion tool
2. manually set certain files to support ARC

I. Xcode's automatic conversion tool
Xcode provides an automatic conversion tool to convert the old source code to the ARC mode.
1. ARC is a feature of the LLVM 3.0 compiler, and the existing project may use the old GCC 4.2 or LLVM-GCC compiler, So first you need to set the use of the LLVM 3.0 Compiler:
(Currently XCode4.5, LLVM 3.0 has been upgraded to LLVM 4.1)

It is best to select Other Warning Flags in Warnings as-Wall, so that the compiler will check all possible Warnings and help us avoid potential problems.

2. The Run Static Analyzer option under Build Options should also be enabled, so that every time Xcode compiles a project, it will Run a Static code analysis tool to check our code


3. Set the "Objective-C Automatic Reference Counting" option to YES. However, the Xcode Automatic conversion tool automatically sets this option. Here, it only describes how to manually set


4. Open Xcode's automatic conversion tool


5. Xcode will display a new window for you to select which files need to be converted

Click the Check button. In the Xcode dialog box that appears, the project cannot be converted to ARC. You need to prepare the conversion. (The detailed description is skipped here)

6. If there are no warnings or errors, a prompt window will pop up:


7. Click Next. After a few seconds, Xcode will prompt the conversion preview of all files to display all changes to the source file. On the left is the modified file, and on the right is the original file. Here you can view Xcode changes in a file to ensure that Xcode does not correct your source file:

Click Save to complete the conversion.

8. After automatic conversion, Xcode will remove all retain, release, and autorelease calls, which may cause other warnings and invalid syntaxes in the code. You must manually modify these calls.
Note: It is best to use Xcode's automatic conversion tool only once. Using it multiple times may cause a strange problem. If you do not convert all files for the first conversion, Xcode will not actually perform any conversion operations when you try to convert the remaining files again later. Therefore, it is best to complete the conversion at one time. You can manually modify the files without conversion.

2. manually enable the ARC of some files

Adding-fobjc-arc to the Compiler Flags column indicates that the. m file's ARC is enabled.

3. Disable the ARC of some files

Adding-fno-objc-arc to the Compiler Flags column indicates disabling the ARC of this. m file.

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.