[swift-evolution] Revise GCD API to conform to API Design Guidelines

Scott Gardner scott.gardner at mac.com
Sat Feb 13 09:48:28 CST 2016

Hello everyone!

I would like to submit the following rough sketch of a proposal to revise the GCD API syntax to adhere to the API Design Guidelines, in order to gauge interest and collect feedback and suggestions.

Here is a preliminary proposal outline:

Author: Scott Gardner


I propose that the Grand Central Dispatch (GCD) API be revised. GCD function signatures use snake-casing and are devoid of parameter names. This syntax does not conform to the Swift API Design Guidelines (“API guidelines”).


The GCD API provides a rich set of capabilities for writing concurrent code. Yet GCD’s syntax can be a barrier to entry for developers, because it does not conform to the API guidelines.

Proposed solution

I propose revising the GCD API to follow the API guidelines. For example, instead of writing the following code to execute an operation asynchronously and then return to the main queue, such as to update the UI...

let concurrentQueue = dispatch_queue_create("com.scotteg.concurrent", DISPATCH_QUEUE_CONCURRENT)

dispatch_async(concurrentQueue) {
  // ...
  dispatch_async(dispatch_get_main_queue()) {
    // ...

…this should be able to written in a more Swifty manner, e.g.,...

let concurrentQueue = GCDQueue(.Concurrent, withIdentifier: "com.scotteg.concurrent")

GCD.enqueueOn(concurrentQueue) {
  // ...
  GCD.enqueueOn(.Main) {
    // ...

Detailed design


Impact on existing code

This would be a wholesale replacement of syntax for the GCD API. A utility should also be created to convert pre-existing GCD code to the new syntax.

Alternatives considered


I would really appreciate your comments and suggestions, and I'd certainly be willing and committed to completing this proposal based on community feedback.


Scott Gardner
http://scotteg.com <http://scotteg.com/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160213/3bf6ad71/attachment.html>

More information about the swift-evolution mailing list