Re: macOS 10.13 suggestion for init() throws
Re: macOS 10.13 suggestion for init() throws
- Subject: Re: macOS 10.13 suggestion for init() throws
- From: Jens Alfke <email@hidden>
- Date: Tue, 28 Feb 2017 13:26:09 -0800
> On Feb 28, 2017, at 11:56 AM, Daryle Walker <email@hidden> wrote:
>
> The problem here is an interface mismatch where Swift has function throw-ability status out-of-band from that function’s parameter list, while Objective-C doesn’t.
Only at the syntax level. Under the hood it works basically the same way as Objective-C, with the error as a hidden ‘out’ parameter. (It pretty much has to, for interoperability purposes.)
So an init() method that throws is a different method with a different signature than one that doesn’t; the two aren’t type-compatible. And I don’t think the two can coexist in one scope, because they’d be ambiguous at the call site. So adding a throwing initializer to NSDocument would require removing the non-throwing one, which can’t be done for backward-compatibility reasons.
I’m sure there are some hacky special-case workarounds that could be done to make this work, if this were a really important aspect of the AppKit API. But I don’t think it is. It may be annoying that the common code shared between your initializers can’t throw, but there are simple workarounds.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden