title: JSONEncoder.encode produces: Thread 1: EXC_BAD_ACCESS in case of inheritance
body: <p>To communicate to my Server I am using Objects of <code>NetworkMessages</code>:</p>
  
  <pre><code>class NetworkMessage: Codable {
  
      var version:Int?;
  
      required init() {
  
      }
  
  }
  
  
  class AddPlayerRequest: NetworkMessage {
  
      var playerName: String?;
      var playerHashedPw:String?;
  
  
  }
  </code></pre>
  
  <p>I am now trying to encode my Object to a String to send it over the network to my Server:</p>
  
  <pre><code>let encoder = JSONEncoder()
  encoder.outputFormatting = .prettyPrinted
  let data = try! encoder.encode(netMsg)
  let stringToSend = String(data: data, encoding: .utf8)
  /* and send the string to the Server here... */
  </code></pre>
  
  <p>Now when I try to send a Object of Type <code>NetworkMessage</code> everything works fine, but when I am using a subclass of <code>NetworkMessage</code>, in this case a <code>CreatePlayerRequest</code>, this error gets thrown:</p>
  
  <blockquote>
    <p>Thread 1: EXC_BAD_ACCESS (code=1, address=0x10)</p>
  </blockquote>
  
  <p>at this line:</p>
  
  <pre><code>let data = try! encoder.encode(netMsg)
  </code></pre>
  
  <p>Thanks for your help!</p>
  
  <p>******* UPDATE *******</p>
  
  <p><strong>I now copied your code and get the error in another line (see Comment):</strong></p>
  
  <pre><code>do {
          let netMsg = AddPlayerRequest()
          netMsg.playerName = "Test"
          netMsg.playerHashedPw = "hynt87t7t76yt=="
  
  
          let encoder = JSONEncoder()
          encoder.outputFormatting = .prettyPrinted
          let data = try encoder.encode(netMsg) /* Thread 1: EXC_BAD_ACCESS */
          let stringToSend = String(data: data, encoding: .utf8)
  
          print(stringToSend ?? "")
      } catch {
          print(error)
  }
  </code></pre>