Skip to content

How to get the type metadata for a field? #26

Answered by Azoy
Azoy asked this question in Q&A
Discussion options

You must be logged in to vote

Cross posting answer: https://github.com/Azoy/Echo/discussions/24#discussioncomment-622404

Azoy answers:

Documentation states it here: https://github.com/Azoy/Echo/wiki/FieldRecord#mangledtypename , but it seems the wiki generator didn't create the code comment for this example. Here:

let metadata = reflect(SomeType.self) as! TypeMetadata
for field in metadata.contextDescriptor.fields.records {
  guard field.hasMangledTypeName else { continue }

  let fieldType = metadata.type(of: field.mangledTypeName)
}

Keep in mind that we need to demangle this type name, so doing this can be expensive, but I do having caching for this mangled name in place to help speed up subsequent demangling on th…

Replies: 1 comment 1 reply

Comment options

Azoy
Apr 18, 2021
Maintainer Author

You must be logged in to vote
1 reply
@Azoy
Comment options

Azoy Apr 18, 2021
Maintainer Author

Answer selected by Azoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant