Hi All.

I’d like to be lazy and leave out the classname on a key path whenever 
possible. I thought that if PartialKeyPath was specified as the argument type, 
that meant the compiler should be able to figure out what the class is, but 
this does not seem to be the case.

Here’s an example that works.

class ThePath {
    var isWinding:Bool?
}

func walk<T>(aPath:T, forKey:PartialKeyPath<T>) {
}

func walkThePath(aPath:ThePath, forKey:PartialKeyPath<ThePath>) {
}

func test() {
    let path = ThePath()
    walkThePath(aPath:path, forKey:\ThePath.isWinding)
    walk(aPath:path, forKey:\ThePath.isWinding)
}

If you do this then it complains:

func test() {
    let path = ThePath()
    walkThePath(aPath:path, forKey:\.isWinding) // Expression type '()' is 
ambiguous without more context
    walk(aPath:path, forKey:\.isWinding)        // Type of expression is 
ambiguous without more context
}

Should I be able to do this?

Thanks!

-Kenny

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to