Noop for Swift's Exhaustive Switch Statements

后端 未结 5 1637
有刺的猬
有刺的猬 2020-11-30 07:17

Swift requires exhaustive switch statements, and that each case have executable code.

\'case\' label in a \'switch\' should have at least one executable

5条回答
  •  广开言路
    2020-11-30 07:45

    According to the book, you need to use break there:

    The scope of each case can’t be empty. As a result, you must include at least one statement following the colon (:) of each case label. Use a single break statement if you don’t intend to execute any code in the body of a matched case.

提交回复
热议问题