logo dotConferences
Menu

The underestimated power of KeyPaths

Vincent Pradeilles at dotSwift 2019

Swift 4 introduced KeyPaths, a literal syntax that allows developers to reference properties, in order to evaluate them at a later time. Their addition went quite under the radar, because both the language and its standard library actually lack the proper tools to really unleash their full potential.

But with the simple addition of a couple helper functions, you’ll see how your code can leverage KeyPaths to become even more concise and declarative.

Slides

To see the slides, you can click here

More details

Code sample:

let words = ["FooBar", "Foo", "Bar"]

words.map(^\.count) // [6, 3, 3]
words.sorted(by: their(\.count)) // ["Foo", "Bar", "FooBar"]