Comparing generic types #44
Answered
by
Azoy
NSExceptional
asked this question in
Q&A
-
Right now, I need to check if a type is Swift's |
Beta Was this translation helpful? Give feedback.
Answered by
Azoy
May 3, 2021
Replies: 1 comment 2 replies
-
The simplest answer I can give is to compare the context descriptors (because there will only ever be 1 of them per type). let array = reflectStruct([Int].self)!.descriptor
// Assuming someType refers to some variable containing `TypeMetadata`
guard someType.contextDescriptor.ptr == array.ptr else {
// The outer type of someType is not an Array
return nil
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
NSExceptional
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The simplest answer I can give is to compare the context descriptors (because there will only ever be 1 of them per type).