protocol DaedalusStorable {}
struct Friend: DaedalusStorable {
let age: Int
let name: String
}
let keyPath = \Friend.name
print("\(keyPath)")
the output is the type information: Swift.KeyPath<TestProject.Friend, Swift.String>. However, in a macOS command-line project, the output is: \Friend.name.
What is the reason for this?
"I want to obtain the name of the KeyPath through a reliable method. Is there any way to do this?
There is no stable public API for getting the name from the KeyPath currently. The printed description is not guaranteed to be stable, and should not be relied upon.
Proper reflection features are expected to be introduced to Swift over time.