[swift-evolution] KVO/KVC in Swift

Colin Cornaby colin.cornaby at mac.com
Thu Dec 3 14:49:42 CST 2015


I looked through the Swift Foundation this morning to see if there was evidence of KVO/KVC, but I didn't find any. Apologies if I missed anything. I'm assuming KVO/KVC is still incompatible with pure Swift, but I was looking for evidence that maybe something had been added in NSObject.

We work in a lot of real time/signal-ly code so we've gotten a lot of good use out of KVO/KVC in Cocoa. I've seen a lot of value in using it when doing UI work as well, either through bindings on OS X (which seems a little unloved these days), or directly by observing key values on iOS. The willSet/didSet functions in Swift is a great step forward for variables in having some of this behavior, but it's still messy in situations where you are dealing with classes you don't control. For example, we're an API vendor, and KVC/KVO is handy for providing a way for a customer to observe changes. But for a pure Swift API we'd have to provide and maintain some sort of larger callback structure, or have a workflow that encourages subclassing with customers adding their own getter/setter handlers.

Are there any plans to add anything like KVO or KVC to pure Swift, with maybe something the bridges to Obj-C KVO? Swift doesn't need to go down the road of full Obj-C style dynamism with method swizzling and all that. But some sort of key based inspection of objects, and language construct for getting callbacks on a property change would be great.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151203/3d5a2a23/attachment.html>


More information about the swift-evolution mailing list