How to silence a warning in swift

前端 未结 4 1284
一整个雨季
一整个雨季 2020-12-04 07:04

I have a piece of code which is generating lots of warnings (deprecated API)

Using clang* I could do

#pragma clang diagnostic push
#pragma clang dia         


        
4条回答
  •  半阙折子戏
    2020-12-04 08:02

    While there’s no way to silence deprecation warnings in Swift for now, technically you can do that for a particular symbol by editing the header file.

    • Copy the deprecated symbol name
    • Select File > Open Quickly
    • Paste the symbol and press Enter

      Make sure the Swift icon is disabled in the Open Quickly box

    • Select File > Show in Finder

    • Change file permissions to allow editing if necessary
    • Edit the deprecation macros for the symbol. See surrounding APIs for reference. E.g. replace:

    __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_6, __MAC_10_10, __IPHONE_3_0, __IPHONE_8_0)

    with

    __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_0)

    Now there’s one less distracting warning you can do nothing about.

    I know, it’s dirty. But if there’s no replacement API available in the current SDK, it should be safe. Once a new version of Xcode comes out, the change will get overwritten and you will see the warning again. Then you can test the new SDK and OS to make sure the deprecated API is still available and did not get a replacement.

    Please comment if you can come up with any downsides.

提交回复
热议问题