From 764c0c8b944574cd63592a452c23865f54b66d0d Mon Sep 17 00:00:00 2001 From: Luo Xiu Date: Mon, 31 Oct 2022 18:34:10 +0800 Subject: [PATCH] fix compile warning, which will be compile error in upcoming swift 6 --- Source/SwiftyJSON/SwiftyJSON.swift | 2 +- Tests/SwiftJSONTests/RawRepresentableTests.swift | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index f7a3f085..e625810e 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -236,7 +236,7 @@ public struct JSON { rawString = string case _ as NSNull: type = .null - case nil: + case Optional.none: type = .null case let array as [Any]: type = .array diff --git a/Tests/SwiftJSONTests/RawRepresentableTests.swift b/Tests/SwiftJSONTests/RawRepresentableTests.swift index 9c628a05..88a70de8 100644 --- a/Tests/SwiftJSONTests/RawRepresentableTests.swift +++ b/Tests/SwiftJSONTests/RawRepresentableTests.swift @@ -84,6 +84,12 @@ class RawRepresentableTests: XCTestCase { if JSON(rawValue: NSObject()) != nil { XCTFail("Should not run into here") } + + do { + let n: Int? = nil + let json = JSON(n as Any) + XCTAssertEqual(json.type, .null) + } } func testArray() {