Skip to content

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

Closed
wants to merge 2 commits into from
Closed

Add NSNull.null() #36

wants to merge 2 commits into from

Conversation

gshahbazian
Copy link

Returns kCFNull and bridges from CFNullRef
as described in Apple documentation.

Returns kCFNull and bridges from CFNullRef
as described in Apple documentation.
@parkera
Copy link
Contributor

parkera commented Dec 5, 2015

This looks great, thanks. One small change - we need to add the new TestNSNull file to build.py so it gets included in our test suite on Linux.

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.
@gshahbazian
Copy link
Author

@parkera thanks for catching that. Added to build.py and changed the test.

@phausler
Copy link
Contributor

phausler commented Dec 5, 2015

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)

@parkera
Copy link
Contributor

parkera commented Dec 5, 2015

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.

@gshahbazian
Copy link
Author

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).

You're correct. What are the implications for this change given that fact?

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.

Gotcha, will update the test.

@phausler
Copy link
Contributor

phausler commented Dec 5, 2015

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.

@parkera
Copy link
Contributor

parkera commented Dec 8, 2015

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.

@parkera
Copy link
Contributor

parkera commented Dec 13, 2015

I think this PR has been superseded by #129.

@parkera parkera closed this Dec 13, 2015
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
[sourcekit] Adopt symbolInfo to implement definition and references
kateinoigakukun pushed a commit to kateinoigakukun/swift-corelibs-foundation that referenced this pull request Apr 29, 2021
Add integration test for building Swift benchmarks with SwiftPM
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.

3 participants