[swift-evolution] [Pitch] Improving KeyPath

Joe Groff jgroff at apple.com
Fri Aug 25 15:35:25 CDT 2017


> On Aug 25, 2017, at 1:27 PM, Eagle Offshore <eagleoffshore at me.com> wrote:
> 
> Reflection mechanisms in general would let one make things like Codable and Keypaths simply a library capability/protocol extension rather than the special case one trick pony it is now.
> 
> More than any other feature discussed, full access to meta data such as memory layouts is the thing I most miss from Objective C.  
> 
> Given reflection/introspection, you can build KVC, Codable, and any number of other clever features yourself if you are so inclined.

Runtime information about type layouts exists in the Swift runtime, and there are many ways we can choose to expose it to programmers. There needs to be some stable runtime-provided interface at the bottom, and KeyPath has some advantages over ObjC-style string-based KVC as that foundation—they're strongly typed, and they don't need to depend on string descriptions of everything being embedded in the binary, which might be undesirable for secrecy reasons. We could allow a type to vend a collection of key paths to all of its fields without having to fully expose source-level details of what those fields are named and how they're laid out, which has been a shortcoming of ObjC's approach for a lot of secrecy-sensitive clients.

> Oh, and traits - want traits for composability.


What do you mean exactly by traits? That's an overloaded term.

-Joe


More information about the swift-evolution mailing list