Reordering tuples with named components


#1

This code works great in Swift 2.2:
------------func foo() -> (a: String, b: Int) { return ("asdf", 4)}
var z: (b: Int, a: String)z = foo()
print("\(z.0)") //4print("\(z.1)") //asdf------------

Notice how I have reordered a and b.
As a result the meaning of .0 and .1 have changed.
Can I, or am I likely to be able to, rely on this behavior going forward into
Swift 2.3, Swift 3, Swift 4 and beyond?


(Joe Groff) #2

I think we're OK with tuple reordering, though it would certainly be more understandable (and more resilient to theoretical future changes) to refer to .b and .a instead of .0 and .1.

-Joe

···

On Apr 5, 2016, at 12:40 PM, tuuranton--- via swift-users <swift-users@swift.org> wrote:

This code works great in Swift 2.2:

------------
func foo() -> (a: String, b: Int) {
    return ("asdf", 4)
}

var z: (b: Int, a: String)
z = foo()

print("\(z.0)") //4
print("\(z.1)") //asdf
------------

Notice how I have reordered a and b.

As a result the meaning of .0 and .1 have changed.

Can I, or am I likely to be able to, rely on this behavior going forward into Swift 2.3, Swift 3, Swift 4 and beyond?