[swift-evolution] Different types for getter and setter
Nevin Brackett-Rozinsky
nevin.brackettrozinsky at gmail.com
Tue Sep 19 10:16:31 CDT 2017
This may sound rather strange in the abstract, but recently I have
encountered two situations where I would like to have a setter that accepts
a different type than the getter returns.
In the first, the getter returns Foo and the setter should accept
“@escaping @autoclosure () -> Foo”, so that the expression assigned to the
property is not evaluated until it is needed. (The closure is stored in a
private property, which the getter evaluates then caches the result.)
In the second, I want a subscript whose getter returns a concrete type (in
my case, subscripting a matrix by row returns an ArraySlice<Element>) while
the setter can accept something more generic (any kind of Collection with
the correct Element type).
Thoughts?
Nevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170919/ce701fca/attachment.html>
More information about the swift-evolution
mailing list