[swift-evolution] [Pitch] Bridging nil to Objective-C Primitives

Douglas Gregor dgregor at apple.com
Tue Feb 14 17:50:24 CST 2017


> On Feb 14, 2017, at 10:41 AM, Jeff Kelley via swift-evolution <swift-evolution at swift.org> wrote:
> 
> On Mon, Feb 13, 2017 at 11:53 PM, Rod Brown <rodney.brown6 at icloud.com <mailto:rodney.brown6 at icloud.com>> wrote:
> I think the biggest problem we're going to face with this one is changes to Objective-C are out of scope for Swift Evolution. Apple tend to be the ones in control of the development of new Objective-C features and compatibility because they control the compiler.
> 
> I don’t think that Objective-C changes are out of bounds when Swift is involved—see my past, accepted proposal at SE-0033 <https://github.com/apple/swift-evolution/blob/master/proposals/0033-import-objc-constants.md>.

For this kind of change to have a real impact, it needs to affect a significant number of frameworks that Swift programmers use. Unless there are automatic heuristics that are *very good*, doing so requires a large amount of manual labor and coordination. So while it is true that Objective-C changes can be in-bounds, from a prioritization/impact perspective, they might not be the right thing to focus on.

> That said, as a request to Apple for this change, I think it's a reasonable idea for Ints, but I'm not sure of its feasibility for other types. Could the API be descriptive enough to cover enough types? (Eg CGRectNull)
> 
> It’s an open-and-shut case for any standard primitive, but structs like CGRect are where it starts to get tricky. I see that CGRect conforms to Equatable when it’s imported into Swift; perhaps that could be enough for this to work? If the translation to and from nil happens in the Swift side, I can see Equatable as a reasonable requirement for the type.

In the most general case, one could imagine providing the names of a pair of C functions to the annotation: one answers the question “is this a nil value?” and the other can be called to produce a nil value.

	- Doug


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170214/a728d88e/attachment.html>


More information about the swift-evolution mailing list