title: Parsing Codable Responses with Alamofire
body: <p>I using the Alamofire Framework, but I don't understand why the variables below are empty.</p>
  
  <p>json:</p>
  
  <pre><code>{
      "ret": true,
      "text": "Oke!",
      "data": {
          "email": “test@mail.com”,
          "nev": "text",
          "zip": "1234",
          "city": "London",
          "street": "text",
          "phone": "5555555555",
          "gdpr": "2"
      }
  }
  </code></pre>
  
  <p>UserDataRootClass.swift:</p>
  
  <pre><code>struct UserDataRootClass : Codable {
  
          let data : UserDataData?
          let ret : Bool?
          let text : String?
  
          enum CodingKeys: String, CodingKey {
                  case data = "data"
                  case ret = "ret"
                  case text = "text"
          }
  
          init(from decoder: Decoder) throws {
                  let values = try decoder.container(keyedBy: CodingKeys.self)
                  data = try? UserDataData(from: decoder)
                  ret = try values.decodeIfPresent(Bool.self, forKey: .ret)
                  text = try values.decodeIfPresent(String.self, forKey: .text)
          }
  
  }
  </code></pre>
  
  <p>UserDataData.swift:</p>
  
  <pre><code>struct UserDataData : Codable {
  
          let city : String?
          let email : String?
          let gdpr : String?
          let nev : String?
          let phone : String?
          let street : String?
          let zip : String?
  
          enum CodingKeys: String, CodingKey {
                  case city = "city"
                  case email = "email"
                  case gdpr = "gdpr"
                  case nev = "nev"
                  case phone = "phone"
                  case street = "street"
                  case zip = "zip"
          }
  
          init(from decoder: Decoder) throws {
                  let values = try decoder.container(keyedBy: CodingKeys.self)
                  city = try values.decodeIfPresent(String.self, forKey: .city)
                  email = try values.decodeIfPresent(String.self, forKey: .email)
                  gdpr = try values.decodeIfPresent(String.self, forKey: .gdpr)
                  nev = try values.decodeIfPresent(String.self, forKey: .nev)
                  phone = try values.decodeIfPresent(String.self, forKey: .phone)
                  street = try values.decodeIfPresent(String.self, forKey: .street)
                  zip = try values.decodeIfPresent(String.self, forKey: .zip)
          }
  
  }
  </code></pre>
  
  <p>NetworkManager.swift:</p>
  
  <pre><code>func postLogin(urlString: String, completion: @escaping (UserDataRootClass?) -&gt; Void) {
          Alamofire.request(urlString).response {
              response in
              guard let data = response.data else { return }
              do {
                  let decoder = JSONDecoder()
                  let loginRequest = try decoder.decode(UserDataRootClass.self, from: data)
                 completion(loginRequest)
              } catch let error {
                  print(error)
                  completion(nil)
              }
          }
      }
  </code></pre>
  
  <p>LoginViewController.swift:</p>
  
  <pre><code>let networkManager = NetworkManager()
  networkManager.postLogin(urlString: "http://demo.com") { (loginRequest) in
  
  if((loginRequest?.ret)!) {
     print(loginRequest) // -&gt; for log
     print(loginRequest?.data.phone)
     }
  
  }
  </code></pre>
  
  <p>The log:</p>
  
  <blockquote>
    <p>UserDataRootClass(data: Optional(.UserDataData(gdpr: nil, email: nil,
    zip: nil, nev: nil, phone: nil, city: nil, street: nil)), ret:
    Optional(true), text: Optional("Oke!"))</p>
  </blockquote>
  
  <p>The <code>loginRequest?.ret</code>, and <code>loginRequest?.text</code> is good, but <code>loginRequest?.data.email</code>, <code>loginRequest?.data.zip</code>... is empty (nil)</p>