【发布时间】:2019-08-05 05:25:23
【问题描述】:
当我确认可解码协议时,如何快速从解码器中解码列表
struct ActiveModuleRespones:Codable {
var Notice:[Notice]?
var Module:[Module]?
public init(from: Decoder) throws {
//decoding here
let container = try from.singleValueContainer()
self.Notice = try? container.decode([Notice].self)
}
}
收到此错误:
Cannot invoke 'decode' with an argument list of type '([[Notice]?])'
请帮忙,
【问题讨论】:
-
第一条规则 - 类、结构和枚举名称以大写字母开头。变量、方法和案例名称以小写字母开头。第二条规则 - 不要将变量命名为与类型名称完全相同。太多的混乱。修复这些问题,你的代码会更好。
-
天哪!我遵循该规则,但仅在本课程中,我们得到
Notice和Module我将尝试使用自定义密钥(CodingKeys),非常感谢您的评论@rmaddy