Skip to content

Commit 4068da3

Browse files
committed
override === for NSNull, it now acts as a singleton. Add one more test case for NSNull with comments.
1 parent 672c2eb commit 4068da3

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Foundation/NSNull.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ public class NSNull : NSObject, NSCopying, NSSecureCoding {
3434
}
3535
}
3636

37-
37+
public func ===(lhs: NSNull?, rhs: NSNull?) -> Bool {
38+
guard let _ = lhs, let _ = rhs else { return false }
39+
return true
40+
}

TestFoundation/TestNSNull.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,16 @@ class TestNSNull : XCTestCase {
3434
let null_3: NSNull? = NSNull()
3535
let null_4: NSNull? = nil
3636

37+
//Check that any two NSNull's are ==
3738
XCTAssertEqual(null_1, null_2)
38-
XCTAssertEqual(null_1, null_3)
3939

40-
XCTAssertNotEqual(null_1, null_4)
40+
//Check that any two NSNull's are ===, preserving the singleton behavior
41+
XCTAssertTrue(null_1 === null_2)
42+
43+
//Check that NSNull() == .Some(NSNull)
44+
XCTAssertEqual(null_1, null_3)
45+
46+
//Make sure that NSNull() != .None
47+
XCTAssertNotEqual(null_1, null_4)
4148
}
4249
}

0 commit comments

Comments
 (0)