消除编译器警告的方法

 

在iOS 不断的升级中,我们经常会遇到一些旧的api或者是属性已经弃用,系统提示采用新的API或者属性替换,可是为了版本上的兼容我们可能还是会用一些就的API或属性,这是系统编译出现黄色的警告,有强迫症的同学看了会非常不舒服。那么如何去掉呢?

1、如果是警告(PerformSelector may cause a leak because its selector is unknown)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
//这里是弃用的API调用
#pragma clang diagnostic pop


2、如果是警告('dismissModalViewControllerAnimated:' is deprecated: first deprecated in iOS 6.0)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
//这里是弃用的属性
#pragma clang diagnostic pop

3、如果是警告(Null passed to a callee that requires a non-null argument)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
//这里是弃用的属性
#pragma clang diagnostic pop

4、如果是警告(Undeclared selector 'DWJQkeyboardWillShow:')

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
//这里是弃用的属性
#pragma clang diagnostic pop

5、如果是警告(Auto property synthesis will not synthesize property 'superColor'; it will be implemented by its superclass, use @dynamic to acknowledge intention)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-property-synthesis"
//这里是弃用的属性
#pragma clang diagnostic pop

6、如果警告类似('automaticallyAdjustsScrollViewInsets' is deprecated: first deprecated in iOS 11.0 - Use UIScrollView's contentInsetAdjustmentBehavior instead)



作者:hotbox
链接:https://www.jianshu.com/p/5fbaae7832f7
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
//这里是弃用的属性
        self.automaticallyAdjustsScrollViewInsets=YES;
#pragma clang diagnostic pop

作者:hotbox
链接:https://www.jianshu.com/p/5fbaae7832f7
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

你可能感兴趣的:(ios)