且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

抑制“'...' 已被弃用";使用 RespondsToSelector 时

更新时间:2023-12-05 10:36:10

我发现 Clang Compiler User's Manual 中的一个示例让我忽略警告:

I found an example in the Clang Compiler User's Manual that lets me ignore the warning:

if ([fileManager respondsToSelector:@selector(removeItemAtPath:error:)]) {
    [fileManager removeItemAtPath:downloadDir error:NULL];
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    [fileManager removeFileAtPath:downloadDir handler:nil];
#pragma clang diagnostic pop
}