Typed Throws with Protocols

Wooow now that's a cool solution! :exploding_head: I honestly didn't know you could use autoclosure that way, although to be fair, I almost never actually use it at all. Time to read up on it.

Do I understand it correctly that because the success param is autoclosure, when you call this:

try child.method() ¿? Error.init

the try child.method() part is converted to a closure?

This will let me significantly improve my code, thanks!

Edit: I've just tried it and unfortunately it doesn't seem to work so great with an async function. In addition to adding an async variant, this is what I had to do at the call site to get it working:

try await (await asyncThrowingCall()) ¿? Error.init

This is because the autoclosure needs the internal await, but also the ¿? operator is async in this case. Do you maybe know a better solution?

Edit 2: it seems that this is a Swift's limitation:

1 Like