[swift-evolution] Swift Closure still inconsistent -- tuple names need to be in curly brackets, single parameter needs to be in parentheses

Vip Malixi vip_m at yahoo.com
Fri Dec 16 17:55:11 CST 2016


When using Closures in Swift, you declare the parameter names inside the curly brackets. How come for tuples you don't, but declare them outside? Also, why do single parameters not need parentheses? This makes Swift inconsistent, e.g.
var oneParameterAndMultipleReturn: ([Int]) -> (even:[Int], odd:[Int]) = { numbers -> ([Int], [Int]) in     var evenNumberArray = [Int]()    var oddNumberArray = [Int]()
    for number in numbers {        number % 2 == 0 ? evenNumberArray.append(number) : oddNumberArray.append(number)    }
    return (evenNumberArray, oddNumberArray)}
for consistency, I suggest tuple names should be in curly brackets where you also declare parameter names. Also, again for consistency and clarity, parameters in Closures should always be surrounded by parentheses, even single parameters:
var oneParameterAndMultipleReturn: ([Int]) -> ([Int], [Int]) = { (numbers) -> (even:[Int], odd:[Int]) in     var evenNumberArray = [Int]()    var oddNumberArray = [Int]()
    for number in numbers {        number % 2 == 0 ? evenNumberArray.append(number) : oddNumberArray.append(number)    }
    return (evenNumberArray, oddNumberArray)}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161216/5e193404/attachment.html>


More information about the swift-evolution mailing list