Suppressing “'…' is deprecated” when using respondsToSelector

后端 未结 5 590
野的像风
野的像风 2020-12-04 17:36

I\'m supporting 10.4+ by picking the most-current API at runtime:

if ([fileManager respondsToSelector:@selector(removeItemAtPath:error:)])
    [fileManager r         


        
5条回答
  •  独厮守ぢ
    2020-12-04 17:54

    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
    }
    

提交回复
热议问题