我通过在运行时选择最新的 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
?
在看到一些答案后,让我澄清一下,将编译器混淆为不知道我在做什么并不是一个有效的解决方案。