I was playing with Swift 4 and Codable
a little bit and got stucked with some scenario having nested protocols which all conform to Codable
.
Simplified example looks like this:
protocol CodableSomething: Codable {}
protocol CodableAnotherThing: Codable {
var something: CodableSomething { get }
}
struct Model: CodableAnotherThing {
var something: CodableSomething
}
This code is making a build errors with Xcode 9 Beta 5:
- Type 'Model' does not conform to protocol 'Decodable'
- Type 'Model' does not conform to protocol 'Encodable'
Now, I wasn't expecting these errors as I understood that conformance to these protocols will be auto-generated by the compiler, when in fact, I couldn't even implement this conformance manually without having build errors. I've also tried several different approaches to solve this kind of a nested model structure with using Codable
but I just couldn't make it work.
My question: Is this a compiler bug (it's still beta) or I'm doing something wrong?