Batch adding compiler flags (like -fno-objc-arc) to source files in an Xcode project.

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:

  1. 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.
  2. Under “Targets”, click the appropriate target (usually there is only one, but it depends on your application’s structure).
  3. Click the “Build Phases” tab at the top.
  4. Expand “Compile Sources” (second container down).
  5. Double-click the source file that you would like to disable ARC for.
  6. 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.

This entry was posted in iOS, Programming, Xcode. Bookmark the permalink.

Leave a Reply