Suppressing "'…' is deprecated" when using respondsToSelector Suppressing "'…' is deprecated" when using respondsToSelector objective-c objective-c

Suppressing "'…' is deprecated" when using respondsToSelector


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}


You could declare a separate file that is designated for calling deprecated methods and set the per-file compiler flags in Xcode to ignore -Wdeprecated-declarations. You can then define a dummy function in that file to call the deprecated methods, and thereby avoid the warnings in your real source files.


I'm not sure if clang is smart enough to catch this, but if it's not, you could try using performSelector:withObject:withObject: or building and invoking an NSInvocation object.