title: Parse Codable classes and avoid repetition
body: <p>I have a JSON response as the following: </p>
  
  <pre><code>{
    "http_status": 200,
    "success": true,
    "has_error": false,
    "error": [
      ""
    ],
    "response": {
      "token": "",
      "verified": false,
      "message": ""
    }
  }
  </code></pre>
  
  <p>As far as i can say for an app API usage http_status, success, has_error, error are shared between all APIS and thus i will create a Codable class to handle it, but the response could be different model, so here is what I'm trying to do.</p>
  
  <p>I have created a general response class as the below, so this class i can use for all apis in the project to avoid duplication of same class but different names:</p>
  
  <pre><code>class GeneralResponse:Codable {
  
      let http_status: Int?
      let success, has_error: Bool?
      let error: [String]?
  
      enum CodingKeys: String, CodingKey {
          case http_status = "http_status"
          case success = "success"
          case has_error = "has_error"
          case error = "error"
      }
  
      init(http_status: Int?, success: Bool?, has_error: Bool?,error: [String]?) {
          self.http_status = http_status
          self.success = success
          self.has_error = has_error
          self.error = error
      }
  
  }
  </code></pre>
  
  <p>Now i have created the response class which will handle for now the registration response:</p>
  
  <pre><code>class RegistrationResponseDetails: Codable {
      let token: String?
      let verified: Bool?
      let message: String?
  
      init(token: String?, verified: Bool?, message: String?) {
          self.token = token
          self.verified = verified
          self.message = message
      }
  }
  </code></pre>
  
  <p>And lets say i need to parse the registration the response so here is what i did, i have created a class and used both of them:</p>
  
  <pre><code>class RegistrationResponse: Codable {
  
      let generalResponse:GeneralResponse?
      let response: RegistrationResponseDetails?
  
      init(generalResponse: GeneralResponse?, response: RegistrationResponseDetails?) {
          self.generalResponse = generalResponse
          self.response = response
      }
  }
  </code></pre>
  
  <p>So i will mainly use RegistrationResponse to parse the response which will parse "generalResponse" which includes http_status, success, has_error, error, and then response will parse the desired response object.</p>
  
  <p>But at some point generalResponse object is always nil and response has the data parsed correctly, what should i do to make generalResponse get parsed without duplication in each api, because in each api i will have generalResponse object so is it possible to solve it ?</p>
  
  <p><strong>Note:</strong> I'm using Alamofire as the networking library.</p>