Swift cannot determine which switch offers are comprehensive

This is an artificial problem because I want to learn more about swift. The fast compiler complains that the following is not exhaustive. Of course, in the general case, he cannot determine whether the allegations of the case are exhaustive. What is the best way I should tell the compiler that my list is exhaustive, for example, in the following case?

let point = (2, 2) 

switch point {    
    case let (x, y) where x == y:
        println("on the x=y line")
    case let (x, y) where x != y:
        println("somewhere else off x=y line") 
}

The only option to add an empty default value: cases?

+4
source share
2 answers

The only option to add an empty default value: cases?

, . , , , . , , , , .

+1

Swift, :

let point = (2, 2)

switch point {
case let (x, y) where x == y:
    print("on the x=y line")
case let (x, y): // Otherwise where x != y:
    print("somewhere else off x=y line")
}

, , , default.

0

Source: https://habr.com/ru/post/1547279/


All Articles