我通过在运行时 Select 最新的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 { … }
的语法提示编译器(叮当声)不要在那一行发出警告?
如果没有,有没有一种方法可以将该行标记为忽略-Wdeprecated-declarations
?
在看到一些答案之后,让我澄清一下,让编译器不知道我在做什么并不是一个有效的解决方案.