[swift-users] Unimplemented types in Swift 4 KeyPaths

Brett Walker brett at brettwalker.net
Mon Jun 19 19:23:02 CDT 2017

Hi all,

In the Swift 4 Keypaths proposal [0161] there seem to be several types 
that are unimplemented (or not working as I expect them to), and I'm not 
sure whether these are simply unfinished in Beta 1, or just ideas that 
weren't accepted.

For instance, according to the proposal AnyKeyPath is supposed to be 
fully type-erased and access properties as optionals at run-time, but 
using it I only get the compile-time error "Type "FooClass" has no 
subscript members", even when applied to objects that still have the 
original type of the KeyPath's root.

Even if I use PartialKeyPath<Root> I get the same error:
var tester = TestClass(name: "steve")
let tester_path = \TestClass.name

let partial_path:PartialKeyPath<TestClass> = tester_path
let name = tester[keyPath: partial_path] /// no subscript members error 

Only when I either use the original path variable, or cast it to 
KeyPath<TestClass, String>, am I able to access the property without an 
error. I am wanting to use KeyPaths in a more generic way, so the 
AnyKeyPath and PartialKeyPath would be helpful. Does anyone have insight 
into the status of these KeyPath types?


More information about the swift-users mailing list