Skip to content

TypeMetadata

tevelee edited this page Jul 25, 2026 · 5 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] 

genericArguments

The generic argument layout for this type.

public var genericArguments: [GenericArgument] 

The result includes pack lengths, metadata packs, witness-table packs, and value arguments when the context uses them. Unknown future argument forms fail closed as an empty result instead of being reinterpreted as a metatype.

genericTypes

The ordinary type arguments for a type-only generic context.

public var genericTypes: [Any.Type] 

This compatibility convenience deliberately returns an empty array for packs, values, non-key parameters, or unknown layouts. Use genericArguments for all modern generic contexts.

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 Typealiases
Global Variables
Global Functions

Clone this wiki locally