相关疑难解决方法(0)

使用respondsToSelector时,禁止"'...'被弃用"

我通过在运行时选择最新的API来支持10.4+:

if ([fileManager respondsToSelector:@selector(removeItemAtPath:error:)])
    [fileManager removeItemAtPath:downloadDir error:NULL];
else
    [fileManager removeFileAtPath:downloadDir handler:nil];
Run Code Online (Sandbox Code Playgroud)

在这种情况下,10.5和up将使用removeItemAtPath:error:,10.4将使用removeFileAtPath:handler:.很好,但我仍然得到旧方法的编译器警告:

warning: 'removeFileAtPath:handler:' is deprecated [-Wdeprecated-declarations]
Run Code Online (Sandbox Code Playgroud)

是否有一种语法if([… respondsToSelector:@selector(…)]){ … } else { … }暗示编译器(Clang)不会在该行上发出警告?

如果没有,有没有办法标记该行被忽略-Wdeprecated-declarations


在看到一些答案之后,让我澄清一下,混淆编译器而不知道我在做什么并不是一个有效的解决方案.

xcode cocoa objective-c clang

56
推荐指数
4
解决办法
2万
查看次数

在Xcode中抑制"已弃用"警告

dismissModalViewControllerAnimated不推荐使用:首先在iOS6.0中弃用

  • 我的部署目标是6.1并且Xcode是5.1.
  • 我想删除6.1模拟器的这个警告.那可能?????
  • 如果我将通过ios 5.1中的选择运行它,那么没有警告.

xcode

6
推荐指数
1
解决办法
6515
查看次数

标签 统计

xcode ×2

clang ×1

cocoa ×1

objective-c ×1