Re: Adding Swift-bridging hints in Obj-C headers?
Re: Adding Swift-bridging hints in Obj-C headers?
- Subject: Re: Adding Swift-bridging hints in Obj-C headers?
- From: Chris Lattner <email@hidden>
- Date: Tue, 16 Sep 2014 10:51:08 -0700
On Sep 16, 2014, at 10:13 AM, Jens Alfke <email@hidden> wrote:
> I'd like my Objective-C framework to be nicer to use from Swift. For example, I'd like method parameters and return values to be declared as non-optional types when a nil value isn't allowed.
>
> Apple seems to have done this with a lot of its classes, but I don't see how; I'd expect to find some annotations in the Obj-C headers but there aren't any. For example, NSDictionary.objectForKey takes parameter type AnyObject, not AnyObject!, but there's nothing special in the declaration of -objectForKey in NSDictionary.h.
>
> In fact, in my classes I've already used __attribute__((nonnull)) to note parameters that aren't allowed to be nil; ideally the Swift translator should recognize that and make the parameter non-optional, but it doesn't look as though it does. I should file an ER on that.
>
> Also, is there any way to view a translation of my class's interfaces into Swift, the way I can with system classes? For example, if I Cmd-click on UIApplication in a Swift source file I get an (automated?) Swift translation of UIApplication.h; whereas if I do that on one of my framework's classes it just opens up its regular .h file.
In Xcode 6 and 6.1, this is handled with an on the side database of optionality and other SDK information and isn’t really extensible. That said, we are extremely interested in bringing the expressive power directly to headers, which would allow you to annotate your own headers, and also allow tools like the Xcode static analyzer to use this information for Objective-C code as well.
This won’t make it into the Xcode 6.1 release, but we’re tracking the ability to do this as an potential feature for a future release of Xcode.
-Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden