我通过在运行时选择最新的API来支持10.4+:
if ([fileManager respondsToSelector:@selector(removeItemAtPath:error:)])
    [fileManager removeItemAtPath:downloadDir error:NULL];
else
    [fileManager removeFileAtPath:downloadDir handler:nil];
在这种情况下,10.5和up将使用removeItemAtPath:error:,10.4将使用removeFileAtPath:handler:.很好,但我仍然得到旧方法的编译器警告:
warning: 'removeFileAtPath:handler:' is deprecated [-Wdeprecated-declarations]
是否有一种语法if([… respondsToSelector:@selector(…)]){ … } else { … }暗示编译器(Clang)不会在该行上发出警告?
如果没有,有没有办法标记该行被忽略-Wdeprecated-declarations?
在看到一些答案之后,让我澄清一下,混淆编译器而不知道我在做什么并不是一个有效的解决方案.
dismissModalViewControllerAnimated不推荐使用:首先在iOS6.0中弃用
Xcode是5.1.