OutputFormatting
The formatting of the output JSON data.
- iOS
- 8.0+
- macOS
- 10.10+
- tvOS
- 9.0+
- watchOS
- 2.0+
struct OutputFormatting
The formatting of the output JSON data.
struct OutputFormatting
s20FoundationEssentials11JSONEncoderC16OutputFormattingV
What are these?93V4I
import FoundationEssentials
class JSONEncoder
JSONEncoder
facilitates the encoding of Encodable
values into JSON.
init()
Initializes self
with default strategies.
var dataEncodingStrategy: JSONEncoder.DataEncodingStrategy { get set }
The strategy to use in encoding binary data. Defaults to .base64
.
var dateEncodingStrategy: JSONEncoder.DateEncodingStrategy { get set }
The strategy to use in encoding dates. Defaults to .deferredToDate
.
var keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy { get set }
The strategy to use for encoding keys. Defaults to .useDefaultKeys
.
var nonConformingFloatEncodingStrategy: JSONEncoder.NonConformingFloatEncodingStrategy { get set }
The strategy to use in encoding non-conforming numbers. Defaults to .throw
.
var outputFormatting: JSONEncoder.OutputFormatting { get set }
The output format to produce. Defaults to []
.
var userInfo: [CodingUserInfoKey : Any] { get set }
Contextual user-provided information for use during encoding.
func encode<T>(_ value: T) throws -> Data where T : Encodable
Encodes the given top-level value and returns its JSON representation.
func encode<T>(_ value: T, configuration: T.EncodingConfiguration) throws -> Data where T : EncodableWithConfiguration
func encode<T, C>(_ value: T, configuration: C.Type) throws -> Data where T : EncodableWithConfiguration, C : EncodingConfigurationProviding, T.EncodingConfiguration == C.EncodingConfiguration
enum DataEncodingStrategy
The strategy to use for encoding Data
values.
enum DateEncodingStrategy
The strategy to use for encoding Date
values.
enum KeyEncodingStrategy
The strategy to use for automatically changing the value of keys before encoding.
enum NonConformingFloatEncodingStrategy
The strategy to use for non-JSON-conforming floating-point values (IEEE 754 infinity and NaN).
protocol Equatable
A type that can be compared for value equality.
protocol ExpressibleByArrayLiteral
A type that can be initialized using an array literal.
protocol OptionSet : RawRepresentable, SetAlgebra
A type that presents a mathematical set interface to a bit set.
protocol RawRepresentable<RawValue>
A type that can be converted to and from an associated raw value.
protocol Sendable
protocol SetAlgebra<Element> : Equatable, ExpressibleByArrayLiteral
A type that provides mathematical set operations.
init(rawValue: UInt)
Creates an OutputFormatting value with the given raw value.
static let prettyPrinted: JSONEncoder.OutputFormatting
Produce human-readable JSON with indented output.
static let sortedKeys: JSONEncoder.OutputFormatting
Produce JSON with dictionary keys sorted in lexicographic order.
static let withoutEscapingSlashes: JSONEncoder.OutputFormatting
By default slashes get escaped (”/” → “/”, “http://apple.com/” → “http://apple.com/”) for security reasons, allowing outputted JSON to be safely embedded within HTML/XML. In contexts where this escaping is unnecessary, the JSON is known to not be embedded, or is intended only for display, this option avoids this escaping.
let rawValue: UInt
The format’s default value.
init()
Creates an empty option set.
init<S>(_ sequence: S) where S : Sequence, Self.Element == S.Element
Creates a new set from a finite sequence of items.
init(arrayLiteral: Self.Element...)
Creates a set containing the elements of the given array literal.
var isEmpty: Bool { get }
A Boolean value that indicates whether the set has no elements.
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.
func contains(_ member: Self) -> Bool
Returns a Boolean value that indicates whether a given element is a member of the option set.
mutating func formIntersection(_ other: Self)
Removes all elements of this option set that are not also present in the given set.
mutating func formSymmetricDifference(_ other: Self)
Replaces this set with a new set containing all elements contained in either this set or the given set, but not in both.
mutating func formUnion(_ other: Self)
Inserts the elements of another set into this option set.
@discardableResult mutating func insert(_ newMember: Self.Element) -> (inserted: Bool, memberAfterInsert: Self.Element)
Adds the given element to the option set if it is not already a member.
func intersection(_ other: Self) -> Self
Returns a new option set with only the elements contained in both this set and the given set.
func isDisjoint(with other: Self) -> Bool
Returns a Boolean value that indicates whether the set has no members in common with the given set.
func isStrictSubset(of other: Self) -> Bool
Returns a Boolean value that indicates whether this set is a strict subset of the given set.
func isStrictSuperset(of other: Self) -> Bool
Returns a Boolean value that indicates whether this set is a strict superset of the given set.
func isSubset(of other: Self) -> Bool
Returns a Boolean value that indicates whether the set is a subset of another set.
func isSuperset(of other: Self) -> Bool
Returns a Boolean value that indicates whether the set is a superset of the given set.
@discardableResult mutating func remove(_ member: Self.Element) -> Self.Element?
Removes the given element and all elements subsumed by it.
mutating func subtract(_ other: Self)
Removes the elements of the given set from this set.
func subtracting(_ other: Self) -> Self
Returns a new set containing the elements of this set that do not occur in the given set.
func symmetricDifference(_ other: Self) -> Self
Returns a new option set with the elements contained in this set or in the given set, but not in both.
func union(_ other: Self) -> Self
Returns a new option set of the elements contained in this set, in the given set, or in both.
@discardableResult mutating func update(with newMember: Self.Element) -> Self.Element?
Inserts the given element into the set.