Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/quicktype-core/src/language/Swift/SwiftRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,15 @@ export class SwiftRenderer extends ConvenienceRenderer {
this.emitBlock(
"if #available(iOS 10.0, OSX 10.12, tvOS 10.0, watchOS 3.0, *)",
() => {
this.emitLine(
"encoder.dateEncodingStrategy = .iso8601",
);
this.emitMultiline(`encoder.dateEncodingStrategy = .custom { date, encoder in
let formatter = ISO8601DateFormatter()
if #available(iOS 11.0, OSX 10.13, tvOS 11.0, watchOS 4.0, *),
date.timeIntervalSince1970.truncatingRemainder(dividingBy: 1) != 0 {
formatter.formatOptions.insert(.withFractionalSeconds)
}
var container = encoder.singleValueContainer()
try container.encode(formatter.string(from: date))
}`);
},
);
} else {
Expand Down
7 changes: 7 additions & 0 deletions test/inputs/schema/date-time.10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"date": "2024-02-29",
"time": "23:59:59.999Z",
"date-time": "2000-02-29T00:30:00.123+02:00",
"union-array": ["2024-02-29", "00:00:00Z"],
"complex-union-array": ["2024-02-29T23:59:59.999Z", "bar", -1]
}
1 change: 1 addition & 0 deletions test/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ export const SwiftLanguage: Language = {
{ "coding-keys-protocol": "CaseIterable" },
["simple-object.json", { "coding-keys-protocol": "CaseIterable" }],
{ "support-linux": "false" },
["date-time.schema", { "support-linux": "false" }],
{ "coding-keys": "false" },
{ "struct-or-class": "class" },
{ sendable: "true" },
Expand Down
Loading