我正在将一个代码从java重写为swift,需要正确地打破多层交换机。在Java中,它看起来像:
block0 : switch (topSwithch) {
case one: {
switch (innerSwitch) {
case insideCase: {
if (something){
break block0;
}
// etc
所以,我要从一个开关断开另一个开关。我怎么用斯威夫特?
最佳答案
这就是斯威夫特的样子。我在操场上用硬编码的变量值做了这个:
let topSwitch = 1
let innerSwitch = 4
let one = 1
let insideCase = 4
let something = true
block0 : switch (topSwitch) { //first switch labeled "block0", switching on topSwitch
case one: //topSwitch is 1, one is 1
switch (innerSwitch) { // switching on innerSwitch
case insideCase: // both are 1
if (something){ // if true
break block0; // break from "block0"
}
default: break // else
}
default: break // else
}