title: How to handle Empty array in codable decode process
body: <p>It works well when "address" array is not empty. But it fails when "address" array is empty. Any help will be highly appreciated. I have struct for Address object. Basically "address" is array of object of type "Address" but when address is empty it fails.</p>
  
  <pre><code>{
      "success": "1",
      "message": "You have succesfully verified your mobile no",
      "details": {
          "customer_id": 825,
          "is_delivery_available": "0",
          "is_registration_complete": "0",
          "is_customer_verified": "0",
          "customer_status": "0",
          "cart_count": "0",
          "name_type": "mr",
          "firstname": "",
          "lastname": "",
          "full_name": "",
          "pincode": "",
          "profile_pic": "",
          "mobile": "8583846677",
          "email": "",
          "address": [
  
          ],
          "referral_code": ""
      }
  }
  </code></pre>
  
  <p>Above is the JSON I am trying to decode using Codable in Swift4.</p>
  
  <pre><code>import Foundation
  
  struct Signup: Codable {
      var success:String?
      var message:String?
      var details:Details?
  
      private enum CodingKeys: String, CodingKey { case success, message, details }
  
      init(from decoder: Decoder) throws {
          let values = try decoder.container(keyedBy: CodingKeys.self)
          success = try values.decode(String.self, forKey: .success)
          message = try values.decode(String.self, forKey: .message)
          if let _details = try? values.decode(Details.self, forKey: .details) {
              details = _details
          }
      }
  }
  
  struct Details: Codable {
      var address:[Address]?
      var cart_count:String?
      var customer_id:String?
      var customer_status:String?
      var email:String?
      var firstname:String?
      var full_name:String?
      var is_customer_verified:String?
      var is_delivery_available:String?
      var is_registration_complete:String?
      var lastname:String?
      var mobile:String?
      var name_type:String?
      var pincode:String?
      var profile_pic:String?
      var referral_code:String?
  
      private enum CodingKeys: String, CodingKey { case address, cart_count, customer_id, customer_status, email, firstname, full_name, is_customer_verified, is_delivery_available, is_registration_complete, lastname, mobile, name_type, pincode, profile_pic, referral_code }
  
      init(from decoder: Decoder) throws {
          let values = try decoder.container(keyedBy: CodingKeys.self)
  
          ****--&gt;&gt;&gt; Issue is in this line. How to handle empty array while decoding. &lt;&lt;&lt;--****
          address = try? values.decode([Address].self, forKey: .address) 
  
          cart_count = try values.decode(String.self, forKey: .cart_count)
          customer_id = try values.decode(String.self, forKey: .customer_id)
          customer_status = try values.decode(String.self, forKey: .customer_status)
          email = try values.decode(String.self, forKey: .email)
          firstname = try values.decode(String.self, forKey: .firstname)
          full_name = try values.decode(String.self, forKey: .full_name)
          is_customer_verified = try values.decode(String.self, forKey: .is_customer_verified)
          is_delivery_available = try values.decode(String.self, forKey: .is_delivery_available)
          is_registration_complete = try values.decode(String.self, forKey: .is_registration_complete)
          lastname = try values.decode(String.self, forKey: .lastname)
          mobile = try values.decode(String.self, forKey: .mobile)
          name_type = try values.decode(String.self, forKey: .name_type)
          pincode = try values.decode(String.self, forKey: .pincode)
          profile_pic = try values.decode(String.self, forKey: .profile_pic)
          referral_code = try values.decode(String.self, forKey: .referral_code)
      }
  }
  
  struct Address: Codable {
      var address_default:String?
      var address_id:String?
      var address_type:String?
      var city:String?
      var customer_id:String?
      var flat_or_house_or_office_no:String?
      var full_address:String?
      var full_name:String?
      var landmark:String?
      var lat:String?
      var lng:String?
      var mobile:String?
      var name_type:String?
      var pincode:String?
      var street_or_society_or_office_name:String?
  }
  </code></pre>
  
  <p>I am stuck into this. How to handle empty array while decoding the json data in Swift4 Codable.</p>