[swift-evolution] [Thoughts?][Phase2] default arguments and trailing closure syntax

Jay Abbott jay at abbott.me.uk
Wed Jan 4 20:25:03 CST 2017


When you have a function with a closure and then another optional default =
nil closure at the end, like this:

open static func animate(identifier: String,
                         duration: Double,
                         update: @escaping AnimationUpdate,
                         completion: AnimationCompletion? = nil) {

You can’t use trailing closure syntax for the update argument when leaving
the completion argument out/default.

This kind of breaks one of the benefits of default arguments, which is that
you can add them to existing released functions without breaking the
calling code. This means you have to add a separate convenience function
without the extra argument, which is annoying and inelegant. Another
annoying thing is that you can easily miss this error if you happen to not
use trailing closure syntax in your tests or other usage, because adding
the extra default argument compiles fine for code that uses normal syntax.

Are there any issues/gotchas if the trailing closure syntax were to work
for the last *specified* argument rather than the last *defined* argument?
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170105/e5ac703a/attachment.html>


More information about the swift-evolution mailing list