• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: macOS 10.13 suggestion for init() throws
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: macOS 10.13 suggestion for init() throws


  • Subject: Re: macOS 10.13 suggestion for init() throws
  • From: Daryle Walker <email@hidden>
  • Date: Wed, 01 Mar 2017 16:19:47 -0500

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

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


  • Next by Date: -forceCancel an NSOperation
  • Next by thread: -forceCancel an NSOperation
  • Index(es):
    • Date
    • Thread