[swift-users] Unimplemented types in Swift 4 KeyPaths

Joe Groff jgroff at apple.com
Wed Jun 21 12:05:35 CDT 2017


> On Jun 19, 2017, at 5:23 PM, Brett Walker via swift-users <swift-users at swift.org> wrote:
> 
> 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 here
> --
> 
> 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?

Support for these did not make it into Xcode 9 beta 1. They are available in swift.org snapshot toolchains, if you want to experiment with them now, and should be in a future seed of Xcode 9.

-Joe


More information about the swift-users mailing list