For those of you using ARC (Automatic Reference Counting) in your Xcode projects, you have probably noticed that some third-party libraries, frameworks, or code snippets haven’t updated to use ARC. Therefore, when you build your project, Xcode complains about manual memory management and you probably see something like this:
Automatic Reference Counting forbids explicit message send of ‘dealloc’
(or ‘release’ or ‘retain’)
Basically, Xcode doesn’t want you to manually manage memory in your application – it wants to let the compiler manage it. You probably already know this, since ARC is an option when creating a new Xcode project.
To disable ARC for a single file:
- In the Project Navigator (left panel, shows all of your project’s files and folders), click your project header. This is usually the top-most item that has your application’s name in bold and something like “1 target, iOS SDK 5.1 ” below it.
- Under “Targets”, click the appropriate target (usually there is only one, but it depends on your application’s structure).
- Click the “Build Phases” tab at the top.
- Expand “Compile Sources” (second container down).
- Double-click the source file that you would like to disable ARC for.
- In the gray popup, type “-fno-objc-arc” (without quotes, with dashes) and click Done. You can also add other compiler flags here.
To disable ARC for multiple files:
Following the steps above, choose multiple files in “Compile Sources” by using the Shift and/or Command keys. Press Enter to open the popup.
This post is the result of a Stack Overflow question I answered.