Pass keyword in Swift
I know that the "pass" keyword in Python will leave a line of code empty where it should contain an executable statement. Is there a similar keyword in Swift?
I am using a switch statement and Swift requires this to be the default case. The code should get to the default instructions in most cases, and I don't want anything to be done in this case.
+3
source to share
2 answers
You can get out of the default case. Swift just wants you to be honest about this to avoid mistakes.
Here's a simple example:
enum Food {
case Banana
case Apple
case ChocolateBar
}
func warnIfUnhealthy(food : Food) {
switch food {
case .ChocolateBar:
println("Don't eat it!")
default:
break
}
}
let candy = Food.ChocolateBar
warnIfUnhealthy(candy)
+3
source to share