This error is shown when an optional is used in a switch statement.
Simply unwrap the variable and everything should work.
switch opts["type"]! {
case "abc":
println("Type is abc")
case "def":
println("Type is def")
default:
println("Type is something else")
}
Edit:
In case you don't want to do a forced unwrapping of the optional, you can use guard
. Reference: Control Flow: Early Exit
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…