<div dir="ltr"><div class="gmail_default"><font face="georgia, serif">I think switch treats (x,y) as two variables instead of a tuple. So it prohibits int_1_1 as it looks like one value only at the first glance. Below two expressions will work.</font></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_default"><font face="georgia, serif">case (int_1_1.0,int_1_1.1): // <<<<</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><font face="georgia, serif">case let foo where foo == int_1_1: // <<<<</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div></blockquote><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline">That why you can use something like</div></font><div><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline"><br></div></font></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline">case (_, 10)</div></font></div></blockquote><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default"><font face="georgia, serif"><br></font></div></blockquote><font face="georgia, serif"><div class="gmail_default" style="font-family:georgia,serif;display:inline">Zhaoxin </div><br></font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 5, 2016 at 5:56 AM, Neil Faiman via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">(Resending — this didn’t get any responses when I sent it a month ago.)<br>
<br>
Swift 2.2 in Xcode 7.3.1.<br>
<br>
Apparently you cannot use a named tuple constant as an expression pattern in a case label.<br>
<br>
func test(x: Int, y: Int) -> Int {<br>
let int_1 = 1<br>
switch x {<br>
case 0:<br>
return 0<br>
case int_1:<br>
return 1<br>
default:<br>
break<br>
}<br>
<br>
let int_1_1: (Int, Int) = (1, 1)<br>
switch (x, y) {<br>
case (0, 0):<br>
return 0<br>
case int_1_1: // <<<<<br>
return 1<br>
default:<br>
return -1<br>
}<br>
}<br>
<br>
error: expression pattern of type '(Int, Int)' cannot match values of type '(Int, Int)'<br>
case int_1_1:<br>
^~~~~~~<br>
<br>
The error message is particularly amusing.<br>
<br>
- Neil Faiman<br>
_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div><br></div>