[swift-evolution] [Proposal] Make `didSet` also available for `let` property, or something new such as `didInit`
shengjia wang
wangshengjia01 at gmail.com
Wed Dec 23 16:02:28 CST 2015
@Félix,
For the first point, the issue you talked about isn't new. We can enter
into that mess easily right now just by changing `let` to `var`.
For the second point, well.. I agree with you and @Michel, thank you guys.
It do make sense, I should've noticed it earlier. This is not an
appropriate solution to make the current "didSet" keyword available for
`let` property.
But I'm still thinking it should not be a problem at all if we add
something new, such as "didInit", which only get called for the very first
time when property is assigned a value.
What do you think?
On Wed, Dec 23, 2015 at 7:39 PM, Michel Fortin <michel.fortin at michelf.ca>
wrote:
> Le 23 déc. 2015 à 11:07, Félix Cloutier via swift-evolution <
> swift-evolution at swift.org> a écrit :
>
> > willSet and didSet are currently not even called from the init method.
>
> And they can't, because in those two blocks you have access to the old
> value as well as the new value. How would that work when you're setting the
> initial value?
>
> var value: Int {
> willSet { print("willSet \(value) -> \(newValue)") }
> didSet { print("didSet \(oldValue) -> \(value)") }
> }
>
>
> --
> Michel Fortin
> https://michelf.ca
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151223/415754bb/attachment.html>
More information about the swift-evolution
mailing list