[swift-evolution] [Pitch] Allow trailing argument labels
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
> 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
> • 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution