ios - 带有参数和 _ 的可编码枚举在编译时失败
问题描述
我注意到我收到了一个非常确定的枚举类型的编译时错误。它可以通过以下方式重现:
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
解决方案
推荐阅读
- javascript - 摩纳哥编辑器 - “[ts] 未终止的正则表达式文字”
- excel - Excel Count Ifs 取决于 2 列的总和
- google-cloud-platform - 如果我查询 Bigquery 视图,如何计算定价?
- python - 如何创建在其行中包含指定字符串的列列表?
- c# - 更改 AutoFac 默认行为
- python - User-defined function with arbitrary number of grouping variables in pandas
- docker - 在 docker 镜像中添加文件
- html - 为什么聚合物的铁选择器对我不起作用?
- linux - 从 Artifactory 安装 RPM 包
- c# - Global.asax.cs Application_Error 中的 MVC 自定义错误代码未按预期工作