我得到了这个代码:
class Person {
let age = 0
}
func createKeyPath() {
let ageKeyPath = \Person.age // Works
}
func createKeyPath(from: ???) { // What can I place here to make it compile?
let ageKeyPath = \from.age
}
我有通用类,我需要在通用具体类型(如 Person)上创建键路径,但我不确定如何基于参数创建键路径。我试过了:
func createKeyPath(from: Person.Type) {
let ageKeyPath = \from.age
}
但它不编译。