[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 09:22:46 CST 2015
Since swift v1.2, we can initialize `let` property in `init()` instead of
being forced to give a value when declare it. This is great !
But every time I run into the case such as the example below:
let view: UIView {
didSet {
/**
* This time, `view` did set ( a.k.a initialized in case of `let`
property), so I want to bind some other actions just after, such as
`setBackgroundColor`. But actually I can't, compiler will complain that
`let` declaration can not be observing properties. So I have to either move
all these "actions" to `init()` or change `view` to a `var` property which
is not necessary at all.
*/
}
}
Actually in swift, I think it's quite commun issue that people run into a
large `init()` method. This approach could make it way better in most cases.
So, I'm wondering why not make `didSet` also available for `let` property,
or maybe even better to add new keyword such as "didInit" which only get
called for first set.
- Victor Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151223/1d0109d5/attachment.html>
More information about the swift-evolution
mailing list