Skip to content

Comparing generic types #44

Answered by Azoy
NSExceptional asked this question in Q&A
May 3, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

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
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Azoy
Comment options

@NSExceptional
Comment options

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