AnyCodable

public struct AnyCodable : Codable
extension AnyCodable: CustomStringConvertible
extension AnyCodable: CustomDebugStringConvertible

A type-erased Codable value.

The AnyCodable type forwards encoding and decoding responsibilities to an underlying value, hiding its specific underlying type.

You can encode or decode mixed-type values in dictionaries and other collections that require Encodable or Decodable conformance by declaring their contained type to be AnyCodable.

See also

AnyEncodable

See also

AnyDecodable
  • The wrapped value of any type.

    Declaration

    Swift

    public let value: Any
  • Creates a type-erased codable value.

    Declaration

    Swift

    public init<T>(_ value: T?)

    Parameters

    value

    The value to wrap, or nil which becomes an empty tuple.

  • Declaration

    Swift

    public var description: String { get }
  • Declaration

    Swift

    public var debugDescription: String { get }