Inconsistencies in use of tuple as a function argument

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Inconsistencies in use of tuple as a function argument

Boon Chew

func testFunctionUsingTuple
()->(Int, String)->Void {
    func t
(x:(Int, String)) {
       
print("\(x.0) \(x.1)")
   
}
   
return t
}

func testFuncUsingArgs
()->(Int, String)->Void {
    func t
(x:Int, y:String) {
       
print("\(x) \(y)")
   
}
   
return t
}

do {
   
var t = testFunctionUsingTuple()
    t
(1, "test")
}

do {
   
var t = testFuncUsingArgs()
    t
(1, "test")
}

func funcUsingTuple
(x:(Int, String)) {
   
print("\(x.0) \(x.1)")
}

func funcUsingArgs
(x:Int, _ y:String) {
   
print("\(x) \(y)")
}

funcUsingTuple
(1, "test") // Won't work - need to use funcUsingTuple((1, "test")) instead
funcUsingArgs
(1, "test3")


In the code example above, notice that when tuple is used as a returned function, it is distinguishable from regular function arguments.  When used in a regular function, a tuple needs to be passed in instead.  Why the inconsistencies?


--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/a50783f9-3780-4d46-93c2-95bf14f0fdf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.