DateEncodingStrategy
The strategy to use for encoding Date
values.
- iOS
- 8.0+
- macOS
- 10.10+
- tvOS
- 9.0+
- watchOS
- 2.0+
enum DateEncodingStrategy
The strategy to use for encoding Date
values.
enum DateEncodingStrategy
s20FoundationEssentials11JSONEncoderC20DateEncodingStrategyO
What are these?322JB
import FoundationEssentials
class JSONEncoder
JSONEncoder
facilitates the encoding of Encodable
values into JSON.
@preconcurrency case custom((Date, any Encoder) throws -> Void)
Encode the Date
as a custom value encoded by the given closure.
case deferredToDate
Defer to Date
for choosing an encoding. This is the default strategy.
case iso8601
Encode the Date
as an ISO-8601-formatted string (in RFC 3339 format).
case millisecondsSince1970
Encode the Date
as UNIX millisecond timestamp (as a JSON number).
case secondsSince1970
Encode the Date
as a UNIX timestamp (as a JSON number).
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 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).
struct OutputFormatting
The formatting of the output JSON data.
protocol Sendable
import Foundation
static func formatted(_ formatter: DateFormatter) -> JSONEncoder.DateEncodingStrategy
import Basics
static var safeISO8601: JSONEncoder.DateEncodingStrategy { get }