0

I'm surprised that something as simple as this doesn't compile (under Xcode 10):

protocol Foo: Codable {}

struct Bar: Codable {
    let foos: [Foo]
}

This fails to compile with:

Type 'Bar' does not conform to protocol 'Encodable'
Type 'Bar' does not conform to protocol 'Decodable'

Shouldn't these be automatically synthesized for such a simple case? Why doesn't this work?

Jason Pepas
  • 424
  • 5
  • 12
  • 1
    https://stackoverflow.com/questions/33112559/protocol-doesnt-conform-to-itself – Mukesh Oct 22 '18 at 05:28
  • 3
    Possible duplicate of [Protocol doesn't conform to itself?](https://stackoverflow.com/questions/33112559/protocol-doesnt-conform-to-itself) – Mukesh Oct 22 '18 at 05:29
  • 1
    Foo is itself codable Protocol so bar doesn't understand how to decode & enocde its value. If you replace Foo with String it will compile fine – Prashant Tukadiya Oct 22 '18 at 05:30

0 Answers0