title: Swift - Decodable fails to decode with an optional value
body: <p>I'm trying to make a simple sign-in request to a backend. The backend returns a JSON object consisting of a status code, a string message every time, and an access token only if the sign-in was successful.<br>
  For that, I have created the following <code>struct</code>:</p>
  
  <pre><code>struct AuthResponse: Decodable {
      enum CodingKeys: String, CodingKey {
          case code, message
          case accessToken = "access_token"
      }
  
      let code: Int, message: String, accessToken: String?
  }
  </code></pre>
  
  <p>When the sign-in is unsuccessful and an access token is not sent by the server, the <code>AuthResponse</code> object manages to decode properly, with <code>nil</code> for the <code>accessToken</code> property, just as I expect it to. For example, the decode is successful for the following response:  </p>
  
  <blockquote>
    <p>code = 400;<br>
     message = "User not registered";  </p>
  </blockquote>
  
  <p>But for a response with an access token, like this one:  </p>
  
  <blockquote>
    <p>"access_token" = <strong>TheAccessToken</strong>;<br>
        code = 200;<br>
        message = "Login successfully";</p>
  </blockquote>
  
  <p>The <code>AuthResponse</code> object does not fails to decode.</p>
  
  <p>Why does this happen? Does that have to do with the fact that the <code>accessToken</code> property is optional? I have also tried overriding the decoding initializer and implementing a <code>decodeIfPresent(_:forKey:)</code> and unwrapping the property but both didn't seem to help.<br>
  Thanks in advance.</p>