Skip to content

TypeMetadata

Azoy edited this page May 6, 2021 · 2 revisions

TypeMetadata

Type metadata refers to those metadata records who declare a new type in Swift. Said metadata records only refer to structs, classes, and enums.

public protocol TypeMetadata: Metadata 

ABI Stability: Stable since the following

| macOS | iOS/tvOS | watchOS | Linux | Windows |
|-------|----------|---------|-------|---------|
| 10.14 | 12.2     | 5.2     | NA    | NA      |

Inheritance

Metadata

Default Implementations

conformances

The list of conformances defined for this type metadata.

public var conformances: [ConformanceDescriptor] 

NOTE: This list is populated once before the program starts with all of the conformances that are statically know at compile time. If you are attempting to load libraries dynamically at runtime, this list will update automatically, so make sure if you need up to date information on a type's conformances, fetch this often. Example:

  let metadata = ...
  var conformances = metadata.conformances
  loadPlugin(...)
  // conformances is now outdated! Refresh it by calling this again.
  conformances = metadata.conformances

contextDescriptor

The base type context descriptor for this type metadata record.

public var contextDescriptor: TypeContextDescriptor 

fieldOffsets

An array of field offsets for this type's stored representation.

public var fieldOffsets: [Int] 

genericTypes

An array of types that represent the generic arguments that make up this type.

public var genericTypes: [Any.Type] 

genericMetadata

An array of metadata records for the types that represent the generic arguments that make up this type.

public var genericMetadata: [Metadata] 

type(of:)

Given a mangled type name to some field, superclass, etc., return the type. Using this is the preferred way to interact with mangled type names because this uses the metadata's generic context and arguments and such to fill in generic types along with caching the mangled name for future use.

public func type(
    of mangledName: UnsafeRawPointer
  ) -> Any.Type? 

Parameters

  • mangledName: The mangled type name pointer to some type in this metadata's reach.

Returns

The type that the mangled type name refers to, if we're able to demangle it.

Types
Protocols
Global Variables
Global Functions
Clone this wiki locally