抑制行特定的XCode编译器警告

时间:2010-05-17 22:00:58

标签: objective-c iphone xcode compiler-warnings

Ben Gottlieb's question类似,我有一些不赞成的电话让我烦恼。有没有办法按线抑制警告?例如:

 if([[UIApplication sharedApplication]
  respondsToSelector:@selector(setStatusBarHidden:withAnimation:)]) {

  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
 } else {
  [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; //causes deprecation warning
 }

我关心的就是那条线。我不想关闭所有弃用警告。我也不愿做suppress specific warnings by file之类的事情。

在其他一些情况下,即使编译器生成警告,我也希望将特定行标记为ok。我本质上想让我的团队知道问题已经处理完毕,并且一遍又一遍地停止对同一行进行窃听。

2 个答案:

答案 0 :(得分:5)

Vincent Gable发布了一个有趣的解决方案。简而言之:

@protocol UIApplicationDeprecatedMethods
- (void)setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated;
@end

if([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarHidden:withAnimation:)]) {
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; 
} else { 
    id<UIApplicationDeprecatedMethods> app = [UIApplication sharedApplication];
    [app setStatusBarHidden:YES animated:NO];
}

答案 1 :(得分:0)

if([[UIApplication sharedApplication]
  respondsToSelector:@selector(setStatusBarHidden:withAnimation:)]) {

  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
 } else {
  [(id)[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
 }