[swift-evolution] Proposal: Expose getter/setters in the same way as regular methods
Michael Henson
mikehenson at gmail.com
Sun Dec 13 18:34:43 CST 2015
Swift-like full KVO/KVC as in Objective-C is a stated long-term goal for
Swift's evolution. The 90% solution might be more straightforward:
class Example {
var member: String
func print() {
print(self.member)
}
}
var example = Example(member: "Hi!")
var example_print_method = example.print
example_print_method()
result:
Hi!
If there were a mechanism for referring to the getter and setter methods on
the var member property as the same kind of self-capturing closures, it
could make simple cases of data binding easier to implement:
var serializeFields = [
"member": example.member#get,
]
var deserializeFields = [
"member": example.member#set,
]
var broadcastValueTo = [
"memberValues": [
example.member#set,
example2.member#set,
example3.member#set,
]
]
viewController.textField.onValueChanged(example.member#set)
Etc.
The "#" notation is just a placeholder for "whatever mechanism is decided
upon", though it does seem to be available and using it postfix makes a
first-glance sense to me in terms of the semantics of expressions.
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151213/375ed0cc/attachment.html>
More information about the swift-evolution
mailing list