Xcode消除编译器警告的方法

在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)

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

你可能感兴趣的:(xcode,macos,ide)