[swift-users] Reordering tuples with named components
Joe Groff
jgroff at apple.com
Tue Apr 5 15:35:02 CDT 2016
> On Apr 5, 2016, at 12:40 PM, tuuranton--- via swift-users <swift-users at 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?
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
More information about the swift-users
mailing list