Strings in Switch Statements: 'String' does not conform to protocol 'IntervalType'

前端 未结 5 954
我在风中等你
我在风中等你 2021-02-05 00:40

I am having problems using strings in switch statements in Swift.

I have a dictionary called opts which is declared as

5条回答
  •  春和景丽
    2021-02-05 01:32

    Try using:

    let str:String = opts["type"] as String
    switch str {
    case "abc":
        println("Type is abc")
    case "def":
        println("Type is def")
    default:
        println("Type is something else")
    }
    

提交回复
热议问题