title: Swift 4 Codable - Bool or String values
body: <p>Looking for some input as to how you would handle the scenario I recently ran into.</p>
  
  <p>I have been using Swift 4s Codable with success but today noticed a crash that I didn't expect.  The API that I am working with, says it returns a <code>boolean</code> for the key <code>manage_stock</code>.</p>
  
  <p>My stubbed struct looks like:</p>
  
  <pre><code>struct Product: Codable {
      var manage_stock: Bool?
  }
  </code></pre>
  
  <p>That works fine, the problem is that the API <strong>sometimes</strong> returns a <code>string</code> instead of a <code>boolean</code>.  </p>
  
  <p>Because of this, my decode fails with:</p>
  
  <pre><code>Expected to decode Bool but found a string/data instead.
  </code></pre>
  
  <p>The string only ever equals <code>"parent"</code> and I want it to equate to <code>false</code>.</p>
  
  <p>I am also fine with changing my struct to <code>var manage_stock: String?</code> if that makes things easier to bring the JSON data in from the API.  But of course, if I change that, my error just changes to:</p>
  
  <pre><code>Expected to decode String but found a number instead.
  </code></pre>
  
  <p>Is there a simple way to handle this mutation or will I need to lose all the automation that <code>Codable</code> brings to the table and implement my own <code>init(decoder: Decoder)</code>.</p>
  
  <p>Cheers</p>