How to obtain the path name of a KeyPath

I have observed that in an iOS project

protocol DaedalusStorable {}

struct Friend: DaedalusStorable {
    let age: Int
    let name: String

let keyPath = \

the output is the type information: Swift.KeyPath<TestProject.Friend, Swift.String>. However, in a macOS command-line project, the output is: \

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?

It seems to be related to the iOS version. In 16.6, you can print the name, but in 15.4.1, you cannot.

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.

1 Like

Thank you for your response, it seems that this feature is only suitable for debugging and not for functional development