Silencing Warnings in Xcode

Lets face it, there are times when you just want to make Xcode stop showing you a particular warning. Turns out this is easy to do if you are compiling using the LLVM GCC. There are few options.

The nuclear option

Select your target and then select build phases. Find the file in the Compile Sources phase (by Eyeballing or by using the filter field in the top right). Double click on the file and enter -w in the box to turn off all warnings for that file.

Obviously you should use this with great care and you should take note of when it’s used. It will not be clear from the code that warning have been silenced.

You can find out more by taking a look at the Clang manual.

The tactial option

You can also silence warnings line by line. In Objective C you can use a clang diagnostic directive. The following example silences depricated calls using the -Wdeprecated-declarations directive. Other option are available.

#pragma clang diagnostic push
#pragma clang diagnostic ignored “-Wdeprecated-declarations”
// Your code goes here
#pragma clang diagnostic pop

Something similar is possible in Swift. For example…

@available(iOS, deprecated: 9.0)
func addressBookStatus() -> ABAuthorizationStatus {
return ABAddressBookGetAuthorizationStatus()