Protocol extension for a specific conforming class
suggest changeYou can write the default protocol implementation for a specific class.
protocol MyProtocol {
func doSomething()
}
extension MyProtocol where Self: UIViewController {
func doSomething() {
print("UIViewController default protocol implementation")
}
}
class MyViewController: UIViewController, MyProtocol { }
let vc = MyViewController()
vc.doSomething() // Prints "UIViewController default protocol implementation"
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents