Skip to content

Implement equality for NSNull #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 13, 2015
Merged

Implement equality for NSNull #129

merged 4 commits into from
Dec 13, 2015

Conversation

kaandedeoglu
Copy link
Contributor

Implemented the isEqual method for NSNull, that always returnstrue for two NSNull instances - thus giving it singleton semantics. (too bad we don't have factory methods or can't return references from initializers)

Added tests.

@kaandedeoglu kaandedeoglu changed the title Implement equality for NSNull - add tests Implement equality for NSNull Dec 11, 2015
let null_4: NSNull? = nil

XCTAssertEqual(null_1, null_2)
XCTAssertEqual(null_1, null_3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NSNull exposed from objc should also have the property of a singleton. So I would also expect that XCTAssertTrue(null_1 === null_2)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but wouldn't that break our NSNull.swift implementation? Should I do a conditional assert?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this particular case it preserves the effective functioning behavior of the "singleton-ness" of NSNull without needing a factory pattern init method. I think it is in the spirit of the API to preserve this and add an overload of the === operator to satisfy the expectation that one construction of NSNull() is to be treated as exactly the same as another construction of NSNull()

@kaandedeoglu
Copy link
Contributor Author

@phausler === is now overridden for NSNull, it acts as a singleton. Also added tests to reflect this as suggested.

@phausler
Copy link
Contributor

looks great!

phausler added a commit that referenced this pull request Dec 13, 2015
Implement equality for NSNull
@phausler phausler merged commit 9df8c0a into swiftlang:master Dec 13, 2015
@parkera parkera mentioned this pull request Dec 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants