AnyEncodable - p2p-org/solana-swift GitHub Wiki
AnyEncodable
A type-erased Encodable
value.
@frozen public struct AnyEncodable: Encodable
The AnyEncodable
type forwards encoding responsibilities
to an underlying value, hiding its specific underlying type.
You can encode mixed-type values in dictionaries
and other collections that require Encodable
conformance
by declaring their contained type to be AnyEncodable
:
let dictionary: [String: AnyEncodable] = [
"boolean": true,
"integer": 42,
"double": 3.141592653589793,
"string": "string",
"array": [1, 2, 3],
"nested": [
"a": "alpha",
"b": "bravo",
"c": "charlie"
],
"null": nil
]
let encoder = JSONEncoder()
let json = try! encoder.encode(dictionary)
Inheritance
CustomDebugStringConvertible
, CustomStringConvertible
, Encodable
, Equatable
, Hashable
Initializers
init(_:)
public init<T>(_ value: T?)
Properties
value
public let value: Any
description
public var description: String
debugDescription
public var debugDescription: String
Methods
hash(into:)
public func hash(into hasher: inout Hasher)
Operators
==
public static func == (lhs: AnyEncodable, rhs: AnyEncodable) -> Bool