使用可选值检查枚举值时,出现段错误。
这是错误的:
message?.type == .In
这是对的:
message!.type == .In // after checking for nil of course
发生了什么事?
请您参考如下方法:
好的,我明白了,它正在尝试找到类型为 Optional(MessageType)(我的枚举)的 .In,我猜它不能,因为这是可选的。使用 MessageType.In 而不是语法糖 .In 修复了它。 (如果编译器找不到它,这不应该是编辑器中的错误吗?)
所以现在我有:
message?.type == MessageType.In
有效。
