KVO/KVC in Swift

For our application projects, I've certainly been keeping an eye on alternatives (we're still very early in our Swift transition.) But for applications we're only working on Cocoa platforms, so the need for an alternative hasn't been as pressing (we're just continuing to use KVC/KVO using NSObject subclasses.)

As an API developer as well, I'm a little hesitant to commit to any of the alternatives. There is a lot of advantages in assuming a developer using your API on an Apple platform is familiar with Cocoa (and going forward, that a Swift developer is familiar with Foundation), and any new construct you add outside of that simply adds more learning overhead. There's also the possibility that the dependency we use is incompatible with a version inside the user's application (which can be dealt with, just a little messy.) This also isn't an issue for us at this point (without ABI stability we can't ship a closed source library without a lot of pain, and we're still only supporting Cocoa platforms.)

One of the reasons I'd love to see Apple lead on this is that I'd like to see it as a language paradigm all of our developers will be familiar with. Open source Swift means that we could dramatically expand our developer base of our API to other platforms, but it also means we need to be able to get away from Cocoa functionality.

Glad to see it's on the list of things to do, but also glad to see ABI stability being discussed so much. ABI stability is the biggest stop-ship for us for porting our SDKs to Swift. :)


On Dec 03, 2015, at 01:19 PM, Adrian Kashivskyy <adrian.kashivskyy@me.com> wrote:


Until KVC/KVO is supported, you may be interested in using constructs like Observable<T>. Here are some illustrative libraries that make use of it: SwiftBond/Bond, slazyk/Observable-Swift.

Pozdrawiam – Regards,
Adrian Kashivskyy

Wiadomość napisana przez Chris Lattner <clattner@apple.com> w dniu 03.12.2015, o godz. 22:00:
On Dec 3, 2015, at 12:49 PM, Colin Cornaby <colin.cornaby@mac.com> wrote:
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.

Are there any plans to add anything like KVO or KVC to pure Swift, with maybe something the bridges to Obj-C KVO?

Hi Colin,

This is one of *many* things that we are interested in working on some day, but we need to stay focused on shorter term goals (like getting to ABI stability) to make sure we are successful with those. If you’re working on Apple platforms, Swift does interoperate with the Objective-C KVO implementation, using the “dynamic" keyword.


swift-evolution mailing list