[swift-evolution] [swift-evolution-announce] [Review] SE-0005 Better Translation of Objective-C APIs Into Swift

Brent Royal-Gordon brent at architechies.com
Fri Jan 29 17:03:02 CST 2016

> The review of SE-0005"Better Translation of Objective-C APIs Into Swift" begins now and runs through January 31, 2016. The proposal is available here:

Specific comments:

> 	• When the Objective-C type is a block, the type name is "Block."

I think we should also consider "Handler" to be a type name for a block. The word appears in many Cocoa APIs, and it basically just means "probably-escaping block". Moreover, it's applied *inconsistently*; for instance, older APIs often say "completionHandler" where more recent APIs say "completion". I don't believe it carries much additional meaning and trimming it would improve API consistency.

> extension UIViewController {
>   func dismissAnimated(flag: Bool, completion: (() -> Void)? = nil)
> }

I believe this should be translated as `dismiss(animated flag: Bool, completion: (() -> Void)? = nil)`. (Note the label on the first argument.) This pattern appears throughout the UI frameworks, particularly UIKit, and it always means exactly the same thing. Whether or not the operation is animated is fundamentally an option on the method, not a fundamental aspect of the operation. Though we don't supply a default for it, and I don't suggest we ought to, we very reasonably could.

I don't think there's a very large rule here—just `fooAnimated(_: Bool)` should be `foo(animated: Bool)`.

> 	• What is your evaluation of the proposal?

Overall, I think this dramatically improves most Cocoa APIs. +1.

> 	• Is the problem being addressed significant enough to warrant a change to Swift?


> 	• Does this proposal fit well with the feel and direction of Swift?

Yes, particularly with the introduction of the API Guidelines.

> 	• If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Well, I've tried using RubyCocoa and its ilk; does that count? This is way better than any of that stuff.

> 	• How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

I'd say a quick reading, plus a read-through of the API Guidelines thread and this thread.

Brent Royal-Gordon

More information about the swift-evolution mailing list