Daily iOS
Swift

KeyPath values

In Swift, what exactly does a KeyPath like \.name represent as a value?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

A KeyPath is a value that points at a property of a type (a reference whose existence and type the compiler checks). Passing it where a function goes makes map and sort concise, and KVO and SwiftUI identify properties with it.

Share a question