Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How do I selectively ignore clang's warnings about use of deprecated objective-c implementations?

Ask Question

I'm updating MGSplitViewController for iOS 5.1, and I want to be warned about usage of deprecated Objective-C methods. Unfortunately, MGSplitViewController supports iOS 3.2, so I want to support all deprecated callbacks, but ignore warnings about them.

I've enabled warnings about "Overriding Deprecated Objective-C Methods" ( CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS ) in my target build settings, but I can't ignore it with

#pragma clang diagnostic push
#pragma clang diagnostic ignored "CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS"
- (void) deprecated_objc_method_override {
#pragma clang diagnostic pop

CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS corresponds to -Wdeprecated-implementations, which Xcode doesn't show in its "Quick Help" area. So the following works:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (void) deprecated_objc_method_override {
#pragma clang diagnostic pop
                Another option, if modifying the actually source might not be wanted, is to turn off the warning when compiling specific files (like those that implement the MGSplit classes. For example, passing compiler flags just to those implementation files like -Wno-deprecated-implementations
– Jason Coco
                Jul 16, 2012 at 16:02

There's also the related deprecated-declarations flag. This suppresses warnings like "'foo' is deprecated: first deprecated in OS X 10.10 - Use -bar instead".

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic pop
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.