I believe this is just a ‘nice to have’ shortcut. I wouldn’t mind to have this:
willSet(newValue, oldValue) didSet(newValue, oldValue) $0 for newValue and $1 for oldValue It’s nothing for phase one, so we’ll have to defer this until next year where we’ll start talking about sugar/additional features for Swift 4. -- Adrian Zubarev Sent with Airmail Am 27. August 2016 um 08:47:38, Charlie Monroe via swift-evolution ([email protected]) schrieb: The newValue is already set in the property, so you just use that property. I don't see much benefit in having "newValue" instead of just accessing it: var anonymousUserMode = false { didSet { if oldValue == self.anonymousUserMode { return } renderLoginOverlay(show: newValue) } } And the same goes for willSet, where you have newValue, but not "oldValue", since oldValue is still in the stored property... > On Aug 26, 2016, at 8:20 PM, Eric Miller via swift-evolution > <[email protected]> wrote: > > Just an idea. > > I use didSet a lot, and it'd be nice to have a generic way to access the > newValue. > > For UI modes: > > var anonymousUserMode = false { didSet { > if oldValue == anonymousUserMode { return } > renderLoginOverlay(show: anonymousUserMode) > }} > > For animated display strings: > > var errorMessage: String? = nil { didSet { > if oldValue == errorMessage { return } > errorLabel.text = errorMessage > // Do some sliding or hiding based on the new value > }} > > Has the idea of using $0 / $1 or oldValue / newValue been considered? > > I'd like to be able to write this as: > > var anonymousUserMode = false { didSet { > if oldValue == newValue { return } > renderLoginOverlay(show: newValue) > }} > _______________________________________________ > swift-evolution mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution _______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
