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() {