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.
case (int_1_1.0,int_1_1.1): // <<<< case let foo where foo == int_1_1: // <<<< That why you can use something like case (_, 10) Zhaoxin On Tue, Jul 5, 2016 at 5:56 AM, Neil Faiman via swift-users < swift-users@swift.org> wrote: > (Resending — this didn’t get any responses when I sent it a month ago.) > > Swift 2.2 in Xcode 7.3.1. > > Apparently you cannot use a named tuple constant as an expression pattern > in a case label. > > func test(x: Int, y: Int) -> Int { > let int_1 = 1 > switch x { > case 0: > return 0 > case int_1: > return 1 > default: > break > } > > let int_1_1: (Int, Int) = (1, 1) > switch (x, y) { > case (0, 0): > return 0 > case int_1_1: // <<<< > return 1 > default: > return -1 > } > } > > error: expression pattern of type '(Int, Int)' cannot match values of type > '(Int, Int)' > case int_1_1: > ^~~~~~~ > > The error message is particularly amusing. > > - Neil Faiman > _______________________________________________ > swift-users mailing list > swift-users@swift.org > https://lists.swift.org/mailman/listinfo/swift-users >
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users