[swift-evolution] [Pitch] Allow trailing argument labels

Ross O'Brien narrativium+swift at gmail.com
Wed Feb 22 04:30:39 CST 2017

I'd like to see this, particularly in initialisers. Objective C can have '-
(instanceType) init' and '- (instanceType) initWithQualifier', where Swift
can only have 'init()'.

On Wed, Feb 22, 2017 at 10:24 AM, Patrick Pijnappel via swift-evolution <
swift-evolution at swift.org> wrote:

> I'd like to discuss allowing a trailing 'argument label' without an actual
> argument:
> func adding(_ other: Self, reportingOverflow) -> … // Actual case in
> SE-104 where this came up
> func tableView(_ tableView: UITableView, numberOfSections) -> Int //
> Referenced as tableView(_:numberOfSections)
> As illustrated above, the way we reference functions extends very
> naturally to include these.
> This would be very useful for several cases:
> • Delegate methods, which currently all start with the same prefix, except
> for some odd cases that really actually just needed a trailing argument
> label.
> • Cases where the function is a more specialized version of one with the
> same name, but can't use a flag because the return type is different (e.g.
> reportingOverflow), or the extra flag check is just undesirable. The
> standard library now uses some workarounds to achieve this (e.g. having a
> trailing argument of type void).
> • Function names that just work more naturally with some additional words
> after the last argument. If we allow trailing argument labels, you can form
> any sentence, rounding out the syntax.
> Overall, I think this could be the final missing piece to complete Swift's
> functions-as-sentences approach.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170222/b354310a/attachment.html>

More information about the swift-evolution mailing list