> On Feb 28, 2017, at 4:26 PM, Jens Alfke <[email protected]> wrote:
> 
> 
>> On Feb 28, 2017, at 11:56 AM, Daryle Walker <[email protected] 
>> <mailto:[email protected]>> 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.

A throwable “init()” would require a “try” in front of it. If Swift bans 
non-throwable code from being prefixed with “try”, then the two versions could 
be distinguishable. Can an initializer be used for a closure property (i.e. 
function pointer)? Then in that case there could be a problem, since 
non-throwable functions are subsets are throwable ones (so a closure to a 
throwable method would accept both).

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

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to