PROPOSAL:
I propose the addition of the following new property observers applicable to
all Collection types (Dictionary, Set, and Array):
– willAdd(newValue) { … }
– didAdd(newValue) { … }
– willRemove(oldValue) { … }
– didRemove(oldValue) { … }
where, `newValue` and `oldValue` are immutable.
This would allow one to perform additional work or observer logic to values
added and removed from collections. This model is consistent with Swift syntax
and may perhaps minimize the use of NSNotifications in some situations.
Currently, in order to perform this functionality some filtering and comparison
logic would have to be performed from within a `willSet { … }` and `didSet {
…}` call. This change would not only ease that burden but promote a more
visible and explicit expression that can further improve readability and
traceability of functionality.
EXAMPLE USAGE:
var list = [objects]() {
willAdd(newValue) {
…
}
didAdd(newValue) {
…
}
}
var list = [key : object]() {
willRemove(oldValue) {
…
}
didRemove(oldValue) {
…
}
}
-----
Sean Alling
[email protected] <mailto:[email protected]>_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution