[swift-evolution] Argument labels in callbacks

Charlie Monroe charlie at charliemonroe.net
Wed Feb 22 02:49:22 CST 2017


This was pointed out during the discussions surrounding this proposal and it was agreed that the type simplification was important.

There were several suggestions how to bring this back using different features - e.g. compound names that would contain the labels. For example:

let callback(success:error:): (Bool, Error?) -> Void = ...
callback(success: true, error: nil)

This way the type itself wouldn't contain the label information, but the name of the variable would.

> On Feb 22, 2017, at 9:41 AM, Goffredo Marocchi via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I am quite interested in this as well, thanks for bringing it up! It was quite disappointing to fall back to multi argument method calls without labels as it was going against the emphasis on the value of labels in the language as well as decreasing readability of what is supposed to be self documenting code.
> 
> Sent from my iPhone
> 
> On 22 Feb 2017, at 08:36, Franklin Schrans via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
>> Hi,
>> 
>> When SE-0111 <https://github.com/apple/swift-evolution/blob/master/proposals/0111-remove-arg-label-type-significance.md> was approved, I noticed the implication it had when using closures as callbacks:
>> 
>> Writing
>>    func foo(completion: (success: Bool) -> Void) {
>>      completion(success: true)
>>    }
>> 
>> is no longer possible, because function types can’t have argument labels anymore, and the function has to be written:
>>    func foo(completion: (Bool) -> Void) {
>>      completion(true)
>>    }
>> 
>> which doesn’t look very nice, especially as the number of the arguments increases.
>> 
>> After talking to Chris Lattner about this, he referred me to this <https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160711/024331.html> email.
>> I was wondering if there's been any further work or plans in restoring the use of argument labels in closures.
>> 
>> - Franklin
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> _______________________________________________
> 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/40c946fa/attachment.html>


More information about the swift-evolution mailing list