-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add NSNull.null() #36
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
Conversation
Returns kCFNull and bridges from CFNullRef as described in Apple documentation.
This looks great, thanks. One small change - we need to add the new TestNSNull file to It would also be nice to have a test which makes sure that this works: Call Foundation API, which calls CF API internally, which returns kCFNull, which is returned from Foundation API, which is == to NSNull. That is - a test which makes sure that the bridging from CF is working. |
Also adds TestNSNull.swift to build.py.
@parkera thanks for catching that. Added to |
Actually i don't think there is a method NSNull.null() in Foundation - the importer seems to remove the factory pattern (which does not yet exist in swift). To mimic the behavior of the objc version the == and === operators could be overloaded for NSNull to make comparison always true. The bridging however looks good (does that unit test actually work on linux? if so we have a module import leaking across) |
Yah unfortunately you can go ahead and import CF even though we want it to be private. I think I was a bit unclear on my request. What I wanted to verify was that any CF code that produces kCFNull, which we then return from Foundation by using the bridging, will be seen as NSNull from Swift. |
You're correct. What are the implications for this change given that fact?
Gotcha, will update the test. |
The missing factory pattern is actually a language extension that would greatly benefit Foundation (and probably other libraries) I have many times run across the need to have a factory init pattern like: /// fictitious syntax
public factory init() -> NSNull {
return unsafeBitCast(kCFNull, NSNull.self)
} This would allow us to have proper abstraction of class clusters and the sort, but it is not yet available in the language. For now the best way to combat this specific issue is to overload the operators of == and === to fake it out into being equal in addition to the bridging. Granted it will still allocate per NSNull but it will be better than the current standings. |
After looking at this again, @phausler is right that we shouldn't add the class method. The reason is that it doesn't exist on Darwin, so it would be incompatible if someone used it for Linux. @gshahbazian can you try the suggestion of overloading the == and === operators? That is, all NSNull instances compare equal to each other. |
I think this PR has been superseded by #129. |
[sourcekit] Adopt symbolInfo to implement definition and references
Add integration test for building Swift benchmarks with SwiftPM
Returns kCFNull and bridges from CFNullRef
as described in Apple documentation.