How to silence a warning in swift

前端 未结 4 1280
一整个雨季
一整个雨季 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 07:42

    Actually, you can suppress these warnings by using @available in the enclosing logical structure (i.e. function/type).

    For example, say you have some code which uses the AddressBook framework, but you're building against iOS 9.

    @available(iOS, deprecated: 9.0)
    func addressBookStatus() -> ABAuthorizationStatus {
        return ABAddressBookGetAuthorizationStatus()
    }
    

    As of Xcode 7.0.1 this will prevent the inline warnings from being displayed.

提交回复
热议问题