diff --git a/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts b/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts index a47b189df1..71d3b103b6 100644 --- a/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts +++ b/packages/quicktype-core/src/language/Swift/SwiftRenderer.ts @@ -1183,14 +1183,9 @@ encoder.dateEncodingStrategy = .formatted(formatter)`); }`); if (this._options.objcSupport === false) { - this.ensureBlankLine(); - this.emitMultiline(` public var hashValue: Int { - return 0 - }`); - this.ensureBlankLine(); this.emitMultiline(` public func hash(into hasher: inout Hasher) { - // No-op + hasher.combine(0) }`); } diff --git a/test/unit/swift-json-null-hashable.test.ts b/test/unit/swift-json-null-hashable.test.ts index 78c9cf9288..d8013b9df3 100644 --- a/test/unit/swift-json-null-hashable.test.ts +++ b/test/unit/swift-json-null-hashable.test.ts @@ -13,7 +13,7 @@ const schema = JSON.stringify({ required: ["value"], }); -test("emits hash(into:) for JSONNull by default", async () => { +test("emits modern Hashable implementation for JSONNull by default", async () => { const schemaInput = new JSONSchemaInput(undefined); await schemaInput.addSource({ name: "TopLevel", schema }); @@ -24,4 +24,6 @@ test("emits hash(into:) for JSONNull by default", async () => { const output = result.lines.join("\n"); expect(output).toContain("public func hash(into hasher: inout Hasher)"); + expect(output).toContain("hasher.combine(0)"); + expect(output).not.toContain("public var hashValue: Int"); });