类型为“字符串"的表达式模式不能与类型为"NSStoryboardSegue.Identifier"的值匹配 [英] Expression pattern of type 'String' cannot match values of type '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
,String
的RawType
.您可能需要将代码更改为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屋!