gpt4 book ai didi

swift - 枚举的段错误

转载 作者:搜寻专家 更新时间:2023-11-01 06:47:29 25 4
gpt4 key购买 nike

使用可选值检查枚举值时,出现段错误。

这是错误的:

message?.type == .In

这是对的:

message!.type == .In // after checking for nil of course

发生了什么事?

最佳答案

好的,我明白了,它正在尝试找到类型为 Optional(MessageType)(我的枚举)的 .In,我猜它不能,因为这是可选的。使用 MessageType.In 而不是语法糖 .In 修复了它。 (如果编译器找不到它,这不应该是编辑器中的错误吗?)

所以现在我有:

message?.type == MessageType.In

有效。

关于swift - 枚举的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28723867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com