Suppressing “'…' is deprecated” when using respondsToSelector

后端 未结 5 603
野的像风
野的像风 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 18:00

    You could just cast fileManager to an idids are able to refer to any Objective-C object, so the compiler isn't supposed to check methods which are called on one:

    [(id)fileManager removeItemAtPath:downloadDir error:NULL];
    

    shouldn't raise any warnings or errors.

    Of course, this raises other problems — namely, you lose all compile-time checking for methods called on the id. So if you misspell you method name, etc, it wont be caught until that line of code is executed.

提交回复
热议问题