Suppressing Xcode Warnings On A Per File Basis

I’m a fanatic about fixing warnings and errors in my code. Whenever I see one I tend to fix it right away which helps make it easy to see new ones when they pop up. However, there are occasions when you just can’t fix them. For instance, you might be using an open source bit of code without the time, knowledge, or commit access to fix a warning. In such cases a lot of warnings in a foreign piece of code can make your own hard to find due to the deluge of yellow icons all over the place. Well, fear not. There is a way to turn off warnings on a per file basis in Xcode.

 

 

Turning off warnings on a per file basis is super simple. All that is required is a compiler flag. Here’s the step by step process.

      1. Open the Project Navigator in Xcode
      2. Click on the Project icon at the very top of the navigator
      3. In the resulting detail pane select the target that you are working with
      4. Select “Build Phases”
      5. Expand “Compile Sources”
      6. In the list locate the file that you’re interested in
      7. Double click the column under the “Compiler Flags” column next to your file
      8. Add a -w to the resulting dialog
      9. Click “Done”
      10. Build your now warnings free project

Compiler Flags are extremely useful in certain situations. Not least among these is turning off ARC on a per file basis. To do so for a file simply add the -fno-objc-arc compiler flag.

Do note that suppressing warnings in your code base should be used judiciously. Be sure that you have a very good reason for doing so. With great power comes great responsibility.