Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mark protocol method as deprecated

How do I make a protocol method appear as deprecated for someone implementing the protocol? I've tried using @available as shown below, but there is no warning shown in Xcode when implementing the protocol method.

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

extension ViewController: TestDelegate {
    func myMethod() -> Bool {
        return true
    }
}
like image 537
Adam Johns Avatar asked Nov 01 '16 21:11

Adam Johns


1 Answers

Info

About attributes

Details

  • Xcode 10.2.1 (10E1001), Swift 5

Code

@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 }
}

Check

enter image description here

like image 147
Vasily Bodnarchuk Avatar answered Nov 02 '22 11:11

Vasily Bodnarchuk