How do I create a noop block for a switch case in Swift?
SwiftSwift Problem Overview
How do I create a noop block for a switch case in Swift? Swift forces you to have at least one executable statement under your case, including default. I tried putting an empty { } but Swift won't take that. Which means that Swift's switch case is not totally translatable between if-else and vice versa because in if-else you are allowed to have empty code inside the condition.
e.g.
switch meat {
case "pork":
print("pork is good")
case "poulet":
print("poulet is not bad")
default:
// I want to do nothing here
}
Swift Solutions
Solution 1 - Swift
default:
break
Apple talks about this keyword in this article. See here, too.
> Although break is not required in Swift, you can still use a break statement to match and ignore a particular case, or to break out of a matched case before that case has completed its execution.