[swift-evolution] API Guidelines for Asynchronous Completion Handlers?
Douglas Gregor
dgregor at apple.com
Thu Dec 3 16:15:07 CST 2015
> On Dec 3, 2015, at 12:32 PM, Dan Stenmark <daniel.j.stenmark at gmail.com> wrote:
>
> There’s a some of debate in the community regarding best practice for asynchronous completion callbacks. These practices include:
>
> - Single Block w/ Mutually Exclusive Result and Error Objects (the current standard convention in Cocoa, though originally designed with Objective-C in mind)
> - Double Block (one for success, one for failure)
> - Swift Enum w/ Associated Objects (as described here: http://www.developerdave.co.uk/2015/09/better-completion-handlers-in-swift/ <http://www.developerdave.co.uk/2015/09/better-completion-handlers-in-swift/>)
>
> Even prior to Swift, Apple’s code guidelines never explicitly addressed this topic. Going forward into the brave new world of Swift, are there going to be new preferred API design guidelines for this?
This is a great point, and there are a number of other issues related to callbacks/closure arguments that would benefit from guidelines. For example, I've seen the “Double Block” case where the second block ends up being a trailing closure, which makes for non-intuitive uses.
- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151203/bcce16d6/attachment-0001.html>
More information about the swift-evolution
mailing list