title: iOS Swift 3 Storing Values To Realm
body: <p>In my app I'm using realm to store and retrieve data's. Here is my API result. I need to store this values to realm database.</p>
  
  <pre><code>{
    "cc": [
      {
        "id": 142,
        "firm": 2,
        "specialization_id": 2,
        "specialization_name": "Alternative",
        "number": "234",
        "title": "Push test",
        "ear": "2012",
        "description": "",
        "status": "Open",
        "open_date": "2017-05-22",
        "close_date": null,
        "closing_comments": null,
        "type_id": 99,
        "type_name": "Tax Reference",
        "record_id": 57,
        "record_name": "Court of India",
        "type": "Court",
        "other_party": [],
        "billing_type": "Retainer",
        "applicants": [
          {
            "type": "Contact",
            "id": 31816,
            "name": "1.Mrs V.Dhanalakshmi &amp;  Another",
            "email": null,
            "firm_id": 2,
            "company_id": null,
            "has_portal_access": false,
            "mobile_number": null,
            "street_address": null,
            "locality": null,
            "city": null,
            "state": null,
            "postal_code": null,
            "landmark": null
          }
        ],
      }
      ]
  }
  </code></pre>
  
  <p>Problem is I can able to store Parent Values like <code>id,firm, specialisation_id,etc,.</code> But I not able to store values like <code>applicants</code> details. Here is my tried code:</p>
  
  <pre><code>import UIKit
  import RealmSwift
  import Realm
  import ObjectMapper
  
  class CaseResponseData: Mappable
  {
      var data:[CaseAreaEntity]?
  
      //Impl. of Mappable protocol
      required convenience init?(map: Map)
      {
          self.init()
      }
  
      func mapping(map: Map)
      {
          data &lt;- map["court_case"]
      }
  }
  
  //Case Details
  class CaseAreaEntity:Object, Mappable
  {
      dynamic var id = 0
      dynamic var firm_id = 0
      dynamic var specialization_id = 0
      dynamic var specialization_name = ""
      dynamic var number = ""
      dynamic var title = ""
      dynamic var case_year = ""
      dynamic var description2 = ""
      dynamic var status = ""
      dynamic var open_date = ""
      dynamic var close_date = ""
      dynamic var closing_comments = ""
      dynamic var case_type_id = 0
      dynamic var case_type_name = ""
      dynamic var court_record_id = 0
      dynamic var court_record_name = ""
      dynamic var court_type = ""
      dynamic var client_type = ""
      dynamic var billing_type = ""
      dynamic var referred_by = ""
      var applicants = List&lt;ApplicantsEntity&gt;()
  
  
      //Impl. of Mappable protocol
      required convenience init?(map: Map)
      {
          self.init()
      }
  
      override static func primaryKey() -&gt; String?
      {
          return "id"
      }
  
  
      func mapping(map: Map)
      {
          id &lt;- map["id"]
          firm_id  &lt;- map["firm_id"]
          specialization_id    &lt;- map["specialization_id"]
          specialization_name &lt;- map["specialization_name"]
          number &lt;- map["number"]
          title &lt;- map["title"]
          case_year &lt;- map["case_year"]
          description2 &lt;- map["description"]
          status &lt;- map["status"]
          open_date &lt;- map["open_date"]
          close_date &lt;- map["close_date"]
          closing_comments &lt;- map["closing_comments"]
          case_type_id &lt;- map["case_type_id"]
          case_type_name &lt;- map["case_type_name"]
          court_record_id &lt;- map["court_record_id"]
          court_record_name &lt;- map["court_record_name"]
          court_type &lt;- map["court_type"]
          client_type &lt;- map["client_type"]
          billing_type &lt;- map["billing_type"]
          referred_by &lt;- map["referred_by"]
          applicants &lt;- map["applicants"]
      }
  }
  //Applicants Details
  class ApplicantsEntity: Object,Mappable
  {
      dynamic var applicant_id = 0
      dynamic var applicantable_type = ""
      dynamic var id = 0
      dynamic var name = ""
      dynamic var first_name = ""
      dynamic var last_name = ""
      dynamic var email = ""
      dynamic var firm_id = 0
      dynamic var company_id = 0
      dynamic var has_portal_access = Bool()
      dynamic var mobile_number = ""
      dynamic var phone_number = ""
      dynamic var fax = ""
      dynamic var website = ""
      dynamic var street_address = ""
      dynamic var locality = ""
      dynamic var city = ""
      dynamic var state = ""
      dynamic var postal_code = ""
      dynamic var landmark = ""
  
      //Impl. of Mappable protocol
      required convenience init?(map: Map)
      {
          self.init()
      }
  
      override static func primaryKey() -&gt; String?
      {
         return "id"
      }
  
      func mapping(map: Map)
      {
          applicant_id &lt;- map["applicant_id"]
          applicantable_type  &lt;- map["applicantable_type"]
          id    &lt;- map["id"]
          name &lt;- map["name"]
          first_name &lt;- map["first_name"]
          last_name &lt;- map["last_name"]
          email  &lt;- map["email"]
          firm_id  &lt;- map["firm_id"]
          company_id  &lt;- map["company_id"]
          has_portal_access  &lt;- map["has_portal_access"]
          mobile_number    &lt;- map["mobile_number"]
          phone_number &lt;- map["phone_number"]
          fax  &lt;- map["fax"]
          website    &lt;- map["website"]
          street_address &lt;- map["street_address"]
          locality  &lt;- map["locality"]
          city    &lt;- map["city"]
          state &lt;- map["state"]
          postal_code  &lt;- map["postal_code"]
          landmark    &lt;- map["landmark"]
      }
  }
  </code></pre>
  
  <p>When Retriving values <code>applicant</code> values are not appearing because those values are not stored. Here is my tried code for creating realm:</p>
  
  <pre><code>let JSON = response.result.value
  let realm:Realm = try! Realm()
  let resData = Mapper&lt;CaseResponseData&gt;().map(JSONObject: JSON)                   
  try! realm.write
  {
    realm.delete(realm.objects(CaseAreaEntity.self))
    realm.add((resData?.data!)!, update: true)
    //realm.create(CaseAreaEntity.self, value: (resData?.data!)!, update: true)
  }
  </code></pre>