Thursday, July 20, 2017 [Tweets] [Favorites]

Swift 4: Key-Value Observation

Skye Freeman:

One of the most exciting additions to the Foundation library in iOS 11 that somehow flew under my radar was the new Swift syntax for key value observation. It’s long been known that the KVO API was one of the more obfuscated and confusing in Cocoa, which makes this change so exciting. Not only is it type safe, but also terse as hell[…]

[…]

let observation = foo.observe(\.string) { (foo, change) in
    print("new foo.string: \(foo.string)")
}

2 Comments

[…] best fix is probably to use the new KVO API, but this issue is worth keeping in mind for other APIs that use C […]

[…] Swift.Codable, Swift 4: Key-Value Observation, Swift’s Error Handling Implementation, Swift 4: Bridging Peephole for “as” […]

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment