禁止 Xcode 中的“已弃用”警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23757078/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Suppress `deprecated` warnings in Xcode
提问by Jayaprada
dismissModalViewControllerAnimated
is deprecated:first deprecated in iOS
6.0
dismissModalViewControllerAnimated
已弃用:在iOS
6.0 中首次弃用
- My deployment target is 6.1 and
Xcode
is 5.1. - I want to remove this warning for 6.1 simulator.Is that Possible?????
- If I will run that by selection in ios 5.1 then no warning.
- 我的部署目标是 6.1 和
Xcode
5.1。 - 我想删除 6.1 模拟器的这个警告。这可能吗??????
- 如果我将在 ios 5.1 中通过选择运行它,那么没有警告。
回答by n00bProgrammer
If I am correct, you simply want to suppress the warnings.
如果我是对的,您只是想抑制警告。
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
This is simply to suppress the warnings. In release builds, you should not use any deprecated functions.
这只是为了抑制警告。在发布版本中,您不应使用任何已弃用的函数。
EDIT: To suppress specific code that invokes warnings, use :
编辑:要抑制调用警告的特定代码,请使用:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self dismissModalViewControllerAnimated:YES];
#pragma clang diagnostic pop
回答by neoscribe
@n00bProgrammer thanks for your answer.
@n00bProgrammer 感谢您的回答。
For those of us who still have code that supports earlier versions of iOS, the way I handle such old code is to wrap the older code in a version macro test as well as to suppress the compiler warnings that result.
对于那些仍然拥有支持较早版本 iOS 的代码的人,我处理这些旧代码的方法是将旧代码包装在版本宏测试中,并抑制由此产生的编译器警告。
Note that sometimes a deprecated item generates an implicit conversion warningthat needs to be suppressed using "-Wconversion".
请注意,有时不推荐使用的项目会生成隐式转换警告,需要使用“-Wconversion”来抑制该警告。
if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wconversion"
[controlCenter.label setLineBreakMode:UILineBreakModeWordWrap];
#pragma clang diagnostic pop
} else {
[controlCenter.label setLineBreakMode:NSLineBreakByWordWrapping];
}
You can find the version checker for older Objective-C code here: SYSTEM_VERSION_LESS_THAN()
您可以在此处找到旧版 Objective-C 代码的版本检查器:SYSTEM_VERSION_LESS_THAN()
You can find the version checker for new Swift and Objective-C code here: Swift and Objective-C version check past iOS 8
你可以在这里找到新的 Swift 和 Objective-C 代码的版本检查器:Swift and Objective-C version check through iOS 8
回答by Anbu.Karthik
use
用
[self presentViewController:loginController animated:YES completion:nil];
or
或者
[self presentModalViewController:loginController animated:YES];
or
或者
[self dismissViewControllerAnimated:NO completion:nil];
回答by Prabhu Natarajan
use thus the following code it works perfect
因此使用以下代码它完美无缺
[self dismissViewControllerAnimated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
Tested and working fine.
经测试,工作正常。
:)
:)