Is key-value observation (KVO) available in Swift?

key-value-observing, swift

Solution

(Edited to add new info): consider whether using the Combine framework can help you accomplish what you wanted, rather than using KVO

Yes and no. KVO works on NSObject subclasses much as it always has. It does not work for classes that don't subclass NSObject. Swift does not (currently at least) have its own native observation system.

(See comments for how to expose other properties as ObjC so KVO works on them)

See the Apple Documentation for a full example.

Problem

If so, are there any key differences that weren't otherwise present when using key-value observation in Objective-C?

Original source

Related problems