[swift-evolution] Overloading assignment operator

Stephen Celis stephen.celis at gmail.com
Mon Dec 7 09:38:15 CST 2015


For what it's worth, you can accomplish a lot of assignment operator
overload behavior via property get/set/willSet/didSet (similar to how Ruby
methods suffixed with "=" are dispatched via dot notation), though it would
require you to design your interface so that "=" is called on a property.

Stephen

On Mon, Dec 7, 2015 at 9:15 AM, Don Wills via swift-evolution <
swift-evolution at swift.org> wrote:

> Thanks to all who replied.  I apologize that my responses were disjoint -
> my spam checker delayed a couple of the messages until this morning.
>
> To those who suggested literal convertibles, I believe Stephen is correct
> in that it is insufficient to accomplish the semantics that I want with the
> syntax I had hoped for.  It is about more than just initialization.  I'll
> probably just use ":=" as the assignment operator.  Not optimal, but it
> works.
>
> Don
>
> > On Dec 6, 2015, at 11:59 AM, Stephen Celis <stephen.celis at gmail.com>
> wrote:
> >
> > I think that his number assignment (via `<~`) depends on the current
> state of `amount`, and that using FloatLiteralConvertible does not provide
> enough information at the call site (since the current value is not
> available in the initializer).
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151207/2457eecb/attachment.html>


More information about the swift-evolution mailing list