73

I have imported the three20 project into my project, and when I upgraded to Xcode 4.2 with iOS 5, a bunch of warnings appeared in the project.

I don't care about them, but they make a lot of noise, and it's easy to miss any real warnings in my project now. Is there a way to disable warnings for those specific libraries?

jscs
  • 63,694
  • 13
  • 151
  • 195
Micah Hainline
  • 14,367
  • 9
  • 52
  • 85

4 Answers4

162
  1. If your third-party libraries are added as a separate target, you can check Inhibit all warnings for that specific target to turn all warnings off.

  2. If your library is added as plain source files to your current target, you can set -w compiler flag for individual sources to mute all warnings in them. You have to go to Build phases menu of your target configuration and set this flag for each source file in Compile Sources section by double clicking on each file end entering -w flag. enter image description here

iHunter
  • 6,205
  • 3
  • 38
  • 56
  • 12
    This is absolutely the correct approach. Do not modify 3rdparty code, and do not turn off warnings globally. Another similar approach is to move the 3rdparty code into a separate project and build a static lib. That way it can have its own build settings. – Rob Napier Dec 20 '11 at 18:42
  • 1
    Every once in a while, I bumble my way into an answer that I wish I could upvote at least a few times. This is one of those times. – BP. Nov 07 '14 at 19:24
  • [This article](http://adoptioncurve.net/archives/2013/02/selectively-disabling-warnings-with-xcode-compiler-flags/) gives some additional details on the individual files flags. They suggest using `-w -Xanalyzer -analyzer-disable-checker` – KPM Feb 07 '15 at 23:46
  • 1
    I tried this in Xcode 7.2.1 and got an error message suggesting that I replace `-analyzer-disable-checker` with `-analyzer-disable-all-checks`. – bruce1337 Feb 17 '16 at 23:58
  • 10
    What if the libraries are static? I only have a thirdPartyLibraryFile.a under the "Build Phases" > "Link Binary With Libraries". There is no compiler flags option under that section. – jotaEsse Apr 06 '17 at 12:37
  • As an addition: If the target uses Swift, you should also set `Suppress Warnings` in the `Swift Compiler - Warning Policies` to `Yes`. – iComputerfreak May 17 '19 at 13:40
19

If you are using pods, you can add this to your podfile to prevent warnings logging:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'] = "YES"
    end
  end
end
Alaa Eddine Cherbib
  • 1,062
  • 14
  • 17
  • 4
    The shorter solution is to add `inhibit_all_warnings!` up top, as per: https://stackoverflow.com/questions/13208202/ignore-xcode-warnings-when-using-cocoapods – pseudosudo Apr 02 '19 at 21:08
  • 1
    Note that adding the `inhibit_all_warnings!` flag is not recommended, since it will be overridden whenever `pod install` is executed. I'd prefer setting in the Podfile – Luiz Dias Oct 01 '21 at 16:52
8

If the warnings come from the included library or framework header files, you can wrap that include statements like this:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullability-completeness"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
#pragma clang diagnostic pop

Put your warning flag on the second line above. You can lookup a warning flags here: https://clang.llvm.org/docs/DiagnosticsReference.html

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Vladimir Grigorov
  • 10,903
  • 8
  • 60
  • 70
0

If the warnings are coming from a framework (for me it was Rollbar) that was added with Carthage:

  1. Add a new framework target (i.e. RollbarWrapper) to your project and embed it within your application target

enter image description here

  1. Drag the built framework from Carthage/Build/<platform> into Xcode, adding it to the dummy/wrapper framework you just created (RollbarWrapper)

enter image description here

  1. Make sure that the framework (Rollbar) is added to the dummy/wrapper framework (RollbarWrapper) target's Frameworks and Libraries section and is set to Do Not Embed

enter image description here

  1. Go to the Build Settings for the dummy/wrapper framework (RollbarWrapper) and set "Inhibit All Warnings" to Yes

  2. Next, add the framework (Rollbar) to your application target's Frameworks, Libraries, & Embedded Content section and set to Do Not Embed

enter image description here

  1. Finally, for the application target, do the normal Carthage setup (i.e. create a new Run Script Phase to execute the copy-frameworks script to copy the Rollbar framework)

enter image description here

NSExceptional
  • 1,368
  • 15
  • 12