对于实施协议的人,如何使协议方法显示为已弃用?我尝试使用@available
,如下所示,但在实现协议方法时Xcode中没有显示警告。
protocol TestDelegate {
@available(*, deprecated, message: "Don't use this anymore")
func myMethod() -> Bool
}
extension ViewController: TestDelegate {
func myMethod() -> Bool {
return true
}
}
答案 0 :(得分:9)
@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 }
}