I am writing some Swift code (Swift 3.1, Xcode 8.3.2), which includes two enumerations. I believe that I wrote a complete to-do list, but the compiler does not agree with me. My code is a bit complicated, with some related values, etc., so I dropped it to a simple example, as I could, on the playground, for example:
enum Test {
case one
case two
case three
case four
}
let allValues: [Test] = [.one, .two, .three, .four]
let test1 = Test.one
let test2 = Test.two
for i in 0..<4 {
for j in 0..<4 {
let test1 = allValues[i]
let test2 = allValues[j]
switch (test1, test2) {
case (.one, _):
print("one, _")
case (_, .one):
print("_, one")
case (.two, _):
print("two, _")
case (_, .two):
print("_, two")
case (.three, .three):
print("three, three")
case (.three, .four):
print("three, four")
case (.four, .three):
print("four, three")
case (.four, .four):
print("four, four")
//Won't compile with this commented out, but when enabled,
//we never print out "default"
// default:
// print("default")
}
}
}
What prints:
one, _
one, _
one, _
one, _
_, one
two, _
two, _
two, _
_, one
_, two
three, three
three, four
_, one
_, two
four, three
four, four
, , "error: switch , ". , , , , , case .
, , . ?