[swift-users] override-like keyword for default implementations
Nevin Brackett-Rozinsky
nevin.brackettrozinsky at gmail.com
Tue May 16 12:32:30 CDT 2017
There is not.
At some point in the future, I believe the plan is to eventually allow
default implementations to be written in-line within the protocol
declaration itself. In other words, the fact that default implementations
currently must appear in extensions, is a temporary limitation that has not
yet been a priority to address.
Once we gain the ability to define default implementations within protocols
themselves, rather than extensions, then your use-case will “just work” (at
least as long as you control the protocol anyway). I wouldn’t hold my
breath though, as that behavior will not appear this year, and the plans
for next year have not been hashed out yet.
Nevin
On Tue, May 16, 2017 at 11:53 AM, Johannes Weiss via swift-users <
swift-users at swift.org> wrote:
> Hi swift-users,
>
> Is there anything like the `override` keyword for making sure that default
> implementations in protocols are not adding a new function?
>
> An example would be the following:
>
> protocol FooProto {
> func foo()
> }
>
> extension FooProto {
> func foo() { /* <-- can I mark this as being a default
> implementation */
> print("foo default")
> }
> }
>
> Right now, there's a `func foo()` default implementation for `FooProto`
> but if later of `foo` gets refactored to `bar`, we lose the default
> implementation which can lead to problems.
>
> Is there anything in Swift (like the `override` keyword) that allows me to
> say this is a default implementation and not a new method?
>
> Thanks,
> Johannes
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170516/a733c60d/attachment.html>
More information about the swift-users
mailing list