【发布时间】:2021-12-26 22:29:52
【问题描述】:
我注意到我收到了一个非常确定的枚举类型的编译时错误。它可以通过以下方式复制:
enum ThisEnumCompiles {
case stringArgument(_ string: String)
case intArgument(_ int: Int)
}
enum ThisEnumAlsoCompiles: Codable {
case stringArgument(string: String)
case intArgument(int: Int)
}
enum ThisEnumDoesNot: Codable {
case stringArgument(_ string: String)
case intArgument(_ int: Int)
}
在您实际构建之前,XCode 中不会显示最后一个枚举的错误:
<unknown>:0: error: type 'ThisEnumDoesNot' has no member 'stringArgument(string:)'
<unknown>:0: error: type 'ThisEnumDoesNot' has no member 'intArgument(int:)'
我不清楚为什么添加 _ 会使最后一个枚举无法编译,而如果它不符合 Codable 则很好
【问题讨论】:
-
您需要一个自定义编码器,例如:pastebin.com/55XrCnM7