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)}
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to