抑制行特定的XCode编译器警告 [英] Suppressing line specific XCode compiler warnings
问题描述
与 Ben Gottlieb的问题类似,我有一些不赞成的电话是烦我。有没有办法按行抑制警告?例如:
Similar to Ben Gottlieb's question, I have a handful of deprecated calls that are bugging me. Is there a way to suppress warnings by line? For instance:
if([[UIApplication sharedApplication]
respondsToSelector:@selector(setStatusBarHidden:withAnimation:)]) {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
} else {
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; //causes deprecation warning
}
我所关心的就是那条线。我不想关闭所有弃用警告。我也不愿做像按文件压制特定警告。
All I care about is that line. I don't want to turn off all deprecation warnings. I would also rather not do something like suppress specific warnings by file.
在其他一些情况下,即使编译器生成警告,我也希望标记特定行。我本质上想让我的团队知道问题已经处理完毕并且一遍又一遍地停止对同一行进行窃听。
There have been a few other circumstances where I wanted to flag a specific line as okay even though the compiler generates a warning. I essentially want to let my team know that the problem has been handled and stop getting bugged about the same line over and over.
推荐答案
Vincent Gable 发布了一个有趣的解决方案。简而言之:
Vincent Gable has posted an interesting solution. In short:
@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];
}
这篇关于抑制行特定的XCode编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!