Can I simulate traits/mixins in Swift? -
does swift have way of mixing in traits, la scala? section of swift book on using extensions add protocols existing classes comes tantalizingly close. however, since protocols can't contain implementation, can't used mix code class. there way?
as of swift 2.0, yes!
providing default implementations
you can use protocol extensions provide default implementation method or property requirement of protocol. if conforming type provides own implementation of required method or property, implementation used instead of 1 provided extension.
Comments
Post a Comment