Structures
The following structures are available globally.
-
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
orDecodable
conformance by declaring their contained type to beAnyCodable
.See also
AnyEncodable
See also
AnyDecodable
Declaration
Swift
@frozen struct AnyCodable
extension AnyCodable : CustomDebugStringConvertible, CustomStringConvertible, Decodable, Encodable, Equatable, Equatable, ExpressibleByArrayLiteral, ExpressibleByBooleanLiteral, ExpressibleByDictionaryLiteral, ExpressibleByExtendedGraphemeClusterLiteral, ExpressibleByExtendedGraphemeClusterLiteral, ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral, ExpressibleByNilLiteral, ExpressibleByStringInterpolation, ExpressibleByStringLiteral, ExpressibleByStringLiteral, ExpressibleByUnicodeScalarLiteral, ExpressibleByUnicodeScalarLiteral, Hashable, _AnyDecodable, _AnyEncodable
-
A type-erased
Decodable
value.The
AnyDecodable
type forwards decoding responsibilities to an underlying value, hiding its specific underlying type.You can decode mixed-type values in dictionaries and other collections that require
Decodable
conformance by declaring their contained type to beAnyDecodable
:
See morelet json = """ { "boolean": true, "integer": 42, "double": 3.141592653589793, "string": "string", "array": [1, 2, 3], "nested": { "a": "alpha", "b": "bravo", "c": "charlie" }, "null": null } """.data(using: .utf8)! let decoder = JSONDecoder() let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json)
Declaration
Swift
@frozen struct AnyDecodable
extension AnyDecodable : CustomDebugStringConvertible, CustomStringConvertible, Decodable, Equatable, Equatable, Hashable, _AnyDecodable
-
A type-erased
Encodable
value.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 beAnyEncodable
:
See morelet 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)
Declaration
Swift
@frozen struct AnyEncodable
extension AnyEncodable : CustomDebugStringConvertible, CustomStringConvertible, Encodable, Equatable, Equatable, ExpressibleByArrayLiteral, ExpressibleByBooleanLiteral, ExpressibleByDictionaryLiteral, ExpressibleByExtendedGraphemeClusterLiteral, ExpressibleByExtendedGraphemeClusterLiteral, ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral, ExpressibleByNilLiteral, ExpressibleByStringInterpolation, ExpressibleByStringLiteral, ExpressibleByStringLiteral, ExpressibleByUnicodeScalarLiteral, ExpressibleByUnicodeScalarLiteral, Hashable, _AnyEncodable
-
LicenseSpring error.
See moreDeclaration
Swift
struct LSError
extension LSError : CustomNSError, Error, Error, Sendable, Sendable