将协议方法标记为已弃用

Ada*_*hns 17 deprecation-warning swift swift-protocols

对于实现协议的人,如何使协议方法显示为已弃用?我尝试使用@available如下所示,但在实现协议方法时Xcode中没有显示警告.

protocol TestDelegate {
    @available(*, deprecated, message: "Don't use this anymore")
    func myMethod() -> Bool
}

extension ViewController: TestDelegate {
    func myMethod() -> Bool {
        return true
    }
}
Run Code Online (Sandbox Code Playgroud)

Vas*_*huk 10

关于属性:https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Attributes.html#//apple_ref/doc/uid/TP40014097-CH35-ID347

码

@objc
protocol TestDelegate {
    @available(iOS, unavailable)
    func myMethod1() -> Bool

    @available(iOS, unavailable, message: "Don't use this anymore")
    func myMethod2() -> Bool

    @available(iOS, unavailable, renamed: "myMethod4()")
    func myMethod3() -> Bool

    @available(iOS, obsoleted: 10.0)
    func myMethod4() -> Bool

    @available(swift, introduced: 3.0, obsoleted: 4.2)
    func myMethod5() -> Bool

    @available(iOS, introduced: 8.0, obsoleted: 11.0)
    func myMethod6() -> Bool
}

extension ViewController: TestDelegate {

    func myMethod1() -> Bool { return true }
    func myMethod2() -> Bool { return true }
    func myMethod3() -> Bool { return true }
    func myMethod4() -> Bool { return true }
    func myMethod5() -> Bool { return true }
    func myMethod6() -> Bool { return true }
}
Run Code Online (Sandbox Code Playgroud)

校验

在此输入图像描述

细节

xCode 8.1,Swift 3

  • 不推荐使用但未过时呢? (4认同)