a switch bug in swift? - “Switch must be exhaustive, consider adding a default clause.”

前端 未结 3 845
青春惊慌失措
青春惊慌失措 2020-12-21 04:11

I am positive that the following swift code has covered all possibilities, but Xcode keeps telling me that, \"Switch must be exhaustive, consider ad

3条回答
  •  粉色の甜心
    2020-12-21 05:10

    The compiler is unable to conclude about your pattern because it is too complex or too unusual for it. If your pattern would have been more regular like:

    case (true, false, _):
        print("Moved left!!!")
    case (true, true, _):
        print("Moved right!!!")
    case (false, false, _):
        print("Moved up!!!")
    case (false, true, _):
        print("Moved down!!!")
    

    then the compiler would have not complained. It that case it is easy for it to conclude that you covered all the cases.

提交回复
热议问题