Skip to content

Commit

Permalink
Merge pull request SwiftyJSON#675 from zhigang1992/removeNilConvertable
Browse files Browse the repository at this point in the history
Remove nil convertable
  • Loading branch information
zhigang1992 authored Oct 10, 2016
2 parents 5a5928b + 6a017fa commit 7075164
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Source/SwiftyJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ extension JSON: Swift.ExpressibleByArrayLiteral {
}

extension JSON: Swift.ExpressibleByNilLiteral {


@available(*, deprecated, message: "use JSON.null instead. Will be removed in future versions")
public init(nilLiteral: ()) {
self.init(NSNull() as Any)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/BaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ class BaseTests: XCTestCase {
func testNullJSON() {
XCTAssertEqual(JSON(NSNull()).debugDescription,"null")

let json:JSON = nil
let json:JSON = JSON.null
XCTAssertEqual(json.debugDescription,"null")
XCTAssertNil(json.error)
let json1:JSON = JSON(NSNull())
if json1 != nil {
if json1 != JSON.null {
XCTFail("json1 should be nil")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ComparableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class ComparableTests: XCTestCase {
}

func testNil() {
let jsonL1:JSON = nil
let jsonL1:JSON = JSON.null
let jsonR1:JSON = JSON(NSNull())
XCTAssertEqual(jsonL1, jsonR1)
XCTAssertTrue(jsonL1 != "123")
Expand Down
8 changes: 4 additions & 4 deletions Tests/LiteralConvertibleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class LiteralConvertibleTests: XCTestCase {
}

func testNil() {
let jsonNil_1:JSON = nil
XCTAssert(jsonNil_1 == nil)
let jsonNil_1:JSON = JSON.null
XCTAssert(jsonNil_1 == JSON.null)
let jsonNil_2:JSON = JSON(NSNull.self)
XCTAssert(jsonNil_2 != nil)
XCTAssert(jsonNil_2 != JSON.null)
let jsonNil_3:JSON = JSON([1:2])
XCTAssert(jsonNil_3 != nil)
XCTAssert(jsonNil_3 != JSON.null)
}

func testArray() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/PrintableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PrintableTests: XCTestCase {
}

func testNil() {
let jsonNil_1:JSON = nil
let jsonNil_1:JSON = JSON.null
XCTAssertEqual(jsonNil_1.description, "null")
XCTAssertEqual(jsonNil_1.debugDescription, "null")
let jsonNil_2:JSON = JSON(NSNull())
Expand Down
2 changes: 1 addition & 1 deletion Tests/RawTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RawTests: XCTestCase {
}

func testNull() {
let json:JSON = nil
let json:JSON = JSON.null
print(json.rawString())
XCTAssertTrue(json.rawString() == "null")
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SubscriptTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class SubscriptTests: XCTestCase {
var json:JSON = [[[[["num":1]]]]]
json[0, 0, 0, 0, "num"] = 2
XCTAssertEqual(json[[0, 0, 0, 0, "num"]].intValue, 2)
json[0, 0, 0, 0, "num"] = nil
json[0, 0, 0, 0, "num"] = JSON.null
XCTAssertEqual(json[0, 0, 0, 0, "num"].null!, NSNull())
json[0, 0, 0, 0, "num"] = 100.009
XCTAssertEqual(json[0][0][0][0]["num"].doubleValue, 100.009)
Expand Down

0 comments on commit 7075164

Please sign in to comment.