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

前端 未结 5 943
我在风中等你
我在风中等你 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:33

    I had this same error message inside prepareForSegue(), which I imagine is fairly common. The error message is somewhat opaque but the answers here got me on the right track. If anyone encounters this, you don't need any typecasting, just a conditional unwrap around the switch statement:-

    if let segueID = segue.identifier {
        switch segueID {
            case "MySegueIdentifier":
                // prepare for this segue
            default:
                break
        }
    }
    

提交回复
热议问题