mercredi 10 avril 2019

What is the proper way to code Kotlin's by-clause (a.k.a. Class Delegation) in Swift?

I need to re-code in Swift a Kotlin class defined like this:

class A(private val foo: FooInterface = FooBase()) : FooInterface by foo {
  ...
}

Is the only way to achieve that is by directly extending the class A with the FooInterface protocol and redirecting all calls to a local private Foo instance?

extension A: FooInterface {
  func fooFun1() {
    self.privateFooInstance.fooFun1()
  }
}

What is the most concise way to do that?

Aucun commentaire:

Enregistrer un commentaire