Treat Warnings as Errors

Mon, Mar 19

It’s good to keep things clean from the start, whether you are running a simple test, writing a large scale enterprise app or building anything in between. With that in mind, I highly recommend you always configure project settings so the compiler treats warnings as errors – in other words, a warning will result in the same output as an error, no executable created.

To configure Xcode to treat warnings as errors, head over to the Build Settings:

• In the search box look for “warnings”
• Scroll to find the entry “Treat Warnings as Errors”
• Set the value to Yes

Remember, warnings are there for a reason, pointing out potential issues with your code. Why would you choose to ignore them?

3 comments

I use static analyzer in each build ( ssd helps ), but setting warnings as errors won’t work in big projects where you have a lot of external libraries, unless you have time to be a contributor to any lib you use :)
Because changing your own instance of library without contributing this changes is waste of time ( new version comes and you wan’t to update )

I have a rule, “don’t push code with warnings or analyzer errors” ;)

by Krzysztof Zabłocki on Mar 20, 2012. #

You can add the “-w” flag to the conflicting files in the “Build Phases” – “Compile Sources” section of your target. Nevertheless, I think your rule of “don’t pushing code with warnings or analyzer errors” is the way to go ;-)

by Sendoa Portuondo on Jan 23, 2013. #

You can use CocoaPods for external libraries and these flags will not affect those libs.

by arturgrigor on Apr 1, 2014. #