【发布时间】:2018-01-08 17:25:25
【问题描述】:
给定:
struct Foo {
let bar: Bar
}
我得到了一个方便的初始化器来使用:
let foo = Foo(bar: Bar())
但如果Bar 本身不是Codable,或者由于某些其他原因我需要在Foo 上显式实现Codable,那么便利的成员初始化器将不再存在:
struct Foo: Codable {
init(from decoder: Decoder) throws {
}
func encode(to encoder: Encoder) throws {
}
let bar: Bar
}
我得到:
let foo = Foo(bar: Bar())
调用中的参数标签不正确(有 'bar:',预期为 'from:')
这里有可能两全其美吗?
【问题讨论】: