【发布时间】:2010-12-26 11:58:35
【问题描述】:
我通过在运行时选择最新的 API 来支持 10.4+:
if ([fileManager respondsToSelector:@selector(removeItemAtPath:error:)])
[fileManager removeItemAtPath:downloadDir error:NULL];
else
[fileManager removeFileAtPath:downloadDir handler:nil];
在这种情况下,10.5 及更高版本将使用 removeItemAtPath:error:,而 10.4 将使用 removeFileAtPath:handler:。很好,但我仍然收到旧方法的编译器警告:
warning: 'removeFileAtPath:handler:' is deprecated [-Wdeprecated-declarations]
是否有 if([… respondsToSelector:@selector(…)]){ … } else { … } 的语法提示编译器 (Clang) 不在该行发出警告?
如果没有,有没有办法标记 -Wdeprecated-declarations 忽略该行?
看到一些答案后,让我澄清一下,将编译器混淆为不知道我在做什么并不是一个有效的解决方案。
【问题讨论】:
标签: objective-c cocoa xcode clang