title: A codable structure contains a protocol property
body: <p>I have a protocol which is inherited from codable</p>
  
  <pre><code>protocol OrderItem:Codable {
      var amount:Int{get set}
      var isPaid:Bool{get set}
  } 
  </code></pre>
  
  <p>And a struct conform this protocol</p>
  
  <pre><code>struct ProductItem:OrderItem {
      var amount = 0
      var isPaid = false
      var price = 0.0
  }
  </code></pre>
  
  <p>However when I put this structure into a codable structure, I got errors</p>
  
  <pre><code>struct Order:Codable {
      var id:String
      var sn:String = ""
      var items:[OrderItem] = []
      var createdAt:Int64 = 0
      var updatedAt:Int64 = 0
  }
  </code></pre>
  
  <p>The errors are</p>
  
  <pre><code>Type 'Order' does not conform to protocol 'Encodable'
  Type 'Order' does not conform to protocol 'Decodable'
  </code></pre>
  
  <p>But if I change items:[OrderItem] to items:[ProductItem] , everything works!</p>
  
  <p>How can I fix this problem?</p>