プロトコルを実装するクラスを拡張するにはどうすればよいですか?プロトコルに準拠したクラスを拡張しますか?
そのような何か:
protocol proto {
func hey()
}
とproto
に準拠したクラス:
Class MyClass: UIViewController, proto {
func hey() {
print("Hey!")
}
}
、次にようになり、そのクラスの拡張:だから
extension UIViewController where Self:proto {
func test() {
print("I'm extended!")
}
}
self.test()
をMyClass
に呼び出すことができます。
ありがとうございました。