Skip to content

Instantly share code, notes, and snippets.

@mwaterfall
Created May 3, 2011 16:26
Show Gist options
  • Save mwaterfall/953659 to your computer and use it in GitHub Desktop.
Save mwaterfall/953659 to your computer and use it in GitHub Desktop.
Suppressing depreciation warnings that have been addressed
// Depreciation Suppression
@protocol SuppressDepreciationWarning
- (void)setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated; // UIApplication - Deprecated in iPhone OS 3.2
@end
// Hide status bar
if ([UIApplication instancesRespondToSelector:@selector(setStatusBarHidden:withAnimation:)]) {
[SharedApplication setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
} else {
[(id <SuppressDepreciationWarning>)SharedApplication setStatusBarHidden:YES animated:YES]; // Depreciated
}
/*
* Handy preprocessor macro for status bar animation
*/
// Animate status bar - with animation style if possible (iOS 3.2+)
#define SetStatusBarHiddenWithAnimation(hide, ani) if ([UIApplication instancesRespondToSelector:@selector(setStatusBarHidden:withAnimation:)]) [SharedApplication setStatusBarHidden:hide withAnimation:ani]; else [(id <SuppressDepreciationWarning>)SharedApplication setStatusBarHidden:hide animated:YES];
// Usage
SetStatusBarHiddenWithAnimation(NO, UIStatusBarAnimationSlide);
@mwaterfall
Copy link
Author

With new iOS releases, API methods are depreciated and newer (better) methods introduced.

If you want to use these better methods and still support older iOS versions, you'll be stuck with many Xcode depreciation warnings. All build warnings are very useful, however once you have addressed an issue that warning will stick around and clutter up your build results.

Here's a great technique for manually suppressing these warnings when you have handled that particular depreciation.

Source vgable.com/blog/2009/06/15/ignoring-just-one-deprecated-warning/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment