Swift 详尽的 Switch 语句的 Noop [英] Noop for Swift's Exhaustive Switch Statements
问题描述
Swift 需要详尽的 switch 语句,并且每个 case 都有可执行代码.
Swift requires exhaustive switch statements, and that each case have executable code.
'switch' 中的'case' 标签应该至少有一个可执行语句
'case' label in a 'switch' should have at least one executable statement
有没有人找到一种好的方法来处理您实际上不想做任何事情的情况?我可以在里面放一个 println() ,但感觉很脏.
Has anybody settled on a good way to handle the cases where you don't want to actually do anything? I can put a println() in there, but that feels dirty.
推荐答案
根据 书,你需要在那里使用 break
:
According to the book, you need to use break
there:
每个案例的范围不能为空.因此,您必须在每个 case 标签的冒号 (:) 后面至少包含一个语句.如果您不打算在匹配案例的主体中执行任何代码,请使用单个 break
语句.
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.
这篇关于Swift 详尽的 Switch 语句的 Noop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!