iex
01/16/2020, 1:56 PMprotocol ChildViewController where Self: UIViewController { // <--ChildViewController is "interface" and it's constrained to a specific class
func foo()
}
extension ChildViewController {
func foo() { <-- this is basically default interface implementation
print(self.view) <-- here we access a field of the concrete type, i.e. UIViewController
}
}
thana
01/16/2020, 2:01 PMiex
01/16/2020, 5:23 PMelizarov
01/17/2020, 8:20 AMinterface ChildViewController<Self: UIViewController> {
val self: Self
}
fun <Self: UIViewController> ChildViewController<Self>.foo() {
println(self.view)
}
iex
01/17/2020, 4:02 PMinterface MyInterface<T: Fragment> {
val self: T
}
fun <T: Fragment> MyInterface<T>.foo() {
println(self.view)
}
But I still need to add a method to the class (Fragment
) in this case to support this:
override val self: RegisterFragment get() = this
Which is not as nice...