类型为“字符串"的表达式模式不能与类型为"NSStoryboardSegue.Identifier"的值匹配 [英] Expression pattern of type 'String' cannot match values of type 'NSStoryboardSegue.Identifier

查看:138
本文介绍了类型为“字符串"的表达式模式不能与类型为"NSStoryboardSegue.Identifier"的值匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的Swift 3代码转换为Swift4.我收到此错误消息:

I'm trying to convert my Swift 3 code to Swift 4. I get this error message:

字符串"类型的表达模式不能与"NSStoryboardSegue.Identifier"类型的值匹配

Expression pattern of type 'String' cannot match values of type 'NSStoryboardSegue.Identifier

这是我的代码:

override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
    switch segue.identifier {

        case "showVC1":
            // DO SOMETHING
            break

        default:
            break
    }
}

我应使用哪种类型代替字符串"?

Which type should I use instead of "String"?

推荐答案

Swift 4将identifier属性的类型从String?切换为 RawRepresentable StringRawType.您可能需要将代码更改为if语句链,或显式使用rawValue:

Swift 4 switched the type of identifier property from String? to NSStoryboardSegue.Identifier?. The type is RawRepresentable, RawType of String. You may need to change your code to a chain of if statements, or use rawValue explicitly:

switch segue.identifier {
    case let x where x.rawValue == "showVC1":
        // DO SOMETHING
    break
    default:
    break
}

这篇关于类型为“字符串"的表达式模式不能与类型为"NSStoryboardSegue.Identifier"的值匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆