Can I get the keyPath from an initialized object?

I know I can use type(of:) to get the metaType.

for example:

class ST {
    var val = 0
    static var typeName: String {
        return String.init(describing: Self.self)
    }
}

func foo(aThing: ST) {
    let aString = type(of: aThing).typeName
    print(aString)
}

I can do like that to get the meta type.

But How can I use type(of:) to get the keyPath of the object?

let's say I want the the keyPath of val using type(of:) , how can I do it?

i tried to do like:

\type(of: str).typeName

but it doesn't work.

Terms of Service

Privacy Policy

Cookie Policy