Encodable
extension Encodable
Extensions to simplify conversion from Encodable types to dictionaries and JSON strings.
-
Converts the conforming type to a dictionary with string keys and
Sendablevalues.This computed property encodes the instance to JSON data and then converts it to a dictionary.
Declaration
Swift
public var dictionary: [String : any Sendable]? { get }Return Value
An optional dictionary representation of the instance, or
nilif encoding fails -
Converts the conforming type to a pretty-printed JSON string.
This computed property first converts the instance to a dictionary, then formats it as an indented JSON string for readability.
Declaration
Swift
public var prettyJSON: String { get }Return Value
A pretty-printed JSON string representation, or “{}” if conversion fails
View on GitHub