Ben*_*ieb 128 iphone macos xcode warnings
随着所有SDK的浮动,能够为多个SDK和平台构建是很方便的.但是,从3.2跳到3.0甚至偶尔2.x,我经常得到已弃用的警告,涉及已更改或被取代的方法:
warning: 'UIKeyboardBoundsUserInfoKey' is deprecated.
Run Code Online (Sandbox Code Playgroud)
由于我仍然希望保持与旧操作系统的兼容性,并且我还在努力在构建时消除"噪音",是否有办法关闭或禁用这些警告?
man*_*sar 329
由于我还不能在@samiq帖子中添加评论,我想我会扩展它.在使用弃用的东西的函数/方法之前输入提到的指令.然后,您可以在定义函数结束后恢复先前的设置:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- (void) methodUsingDeprecatedStuff {
//use deprecated stuff
}
#pragma GCC diagnostic pop
Run Code Online (Sandbox Code Playgroud)
And*_*ger 141
Clang提供了一个很好的功能,使@manicaesar帖子中的"恢复"步骤独立于初始警告状态:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- (void) methodUsingDeprecatedStuff {
//use deprecated stuff
}
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)
引用Clang 手册:
除了GCC的pragma提供的所有功能外,Clang还允许您推送和弹出当前的警告状态.这在编写将由其他人编译的头文件时特别有用,因为您不知道他们构建了哪些警告标志.
Pau*_*l R 78
尝试-Wno-deprecated-declarations
,或在Xcode中的相应设置,GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS
(专业提示:只需在构建设置中键入"不建议使用"以查找此警告的特定设置).
当前版本的Xcode(例如Xcode 9.2):
古代版本的Xcode(例如Xcode 2.x,3.x):
Joe*_*hes 39
由于我们倾向于需要支持较旧的操作系统,但要注意我们的警告,我想要一个更整洁的方法来做到这一点.我把它放在一起,受到一些Mozilla代码的启发:
#define SILENCE_DEPRECATION(expr) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
expr; \
_Pragma("clang diagnostic pop") \
} while(0)
#define SILENCE_IOS7_DEPRECATION(expr) SILENCE_DEPRECATION(expr)
#define SILENCE_IOS8_DEPRECATION(expr) SILENCE_DEPRECATION(expr)
Run Code Online (Sandbox Code Playgroud)
这允许您执行以下操作:
SILENCE_IOS7_DEPRECATION(return [self sizeWithFont:font constrainedToSize:size]);
Run Code Online (Sandbox Code Playgroud)
它也适用于代码块:
SILENCE_IOS7_DEPRECATION(
view = [[MKPolylineView alloc] initWithPolyline:self];
view.lineWidth = self.lineWidth;
view.strokeColor = self.color;
);
Run Code Online (Sandbox Code Playgroud)
此外,当您放弃对iOS 7之前的设备的支持时,您可以轻松搜索代码以查找要修复的弃用用法.
sam*_*miq 29
您还可以使用禁止每个文件的警告
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Run Code Online (Sandbox Code Playgroud)
这反过来使得它比一次和一起抑制所有警告更好一点......毕竟你已经知道你在做什么了.
小智 16
如果要静音警告实现弃用方法或实现弃用类,请使用:
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-implementations" // code #pragma clang diagnostic pop
如果您想全面检查一段代码中的各种弃用情况。请使用-Wdeprecated标志,如下所示:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
- (void) methodUsingDeprecatedStuff {
//use deprecated stuff
}
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
59860 次 |
最近记录: |