title: Create new Realm List and add items
body: <p>I make a <code>API</code> request with <code>Alamofire</code> , I then get a response in <code>JSON</code> format, I then parse the <code>JSON</code> into a <code>NSDictionary</code> to get to the data I want.
  The data I get is four <code>Arrays</code> of different items.
  I want to the create a new List in Realm to save these items in.
  Here are my Realm Object Classes :</p>
  
  <pre><code>class ListOfDefinitions: Object {
   let listOfItems = List&lt;Item&gt;()
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Item: Object {
  
  dynamic var AverageCost = Int()
  dynamic var Barcode = ""
  dynamic var Description = ""
  dynamic var InternalUnique = Int()
  dynamic var LastCost = Int()
  dynamic var LimitToMainRegionUnique = Int()
  dynamic var Notes = ""
  dynamic var StockCategoryUnique = Int()
  dynamic var StockCode = ""
  dynamic var StockGroupUnique = Int()
  dynamic var UnitDescriptor = ""
  }
  </code></pre>
  
  <p>Here is my code on how I handle the JSON response and where I want to save the data in my code.</p>
  
  <pre><code> var newItemInStockList : ListOfDefinitions!   // declared in the class
   let newItemInStock = Item()
  
  
  .responseJSON { response in
  
  
  
              switch response.result {
  
              case .Success(let JSON):
                 // print("Success with JSON: \(JSON)")
  
                  let response = JSON as! NSDictionary
  
  
  
                  let responseParams = response.objectForKey("ResponseParameters") as! NSDictionary
                  //print(responseParams)
  
                  //let stockItemGroupList = responseParams.objectForKey("StockItemGroupList")
  
                  let stockItemList = responseParams.objectForKey("StockItemList") as! NSDictionary
                  //print(stockItemList)
  
                  let listofDefinitions = stockItemList.objectForKey("ListofDefinitions") as! NSArray
                  print(listofDefinitions.count)
  
  
                  for defJson in listofDefinitions {
  
                      print(defJson["Description"])
  
                      someString = defJson["Description"] as! String
                      print(someString)
  // Because there are 4 arrays of items this for loop will be red 4 times, each time it is red I want o create a new list and add the items to the list
  //  This comment area is where I tried to create a new list and then .append the items in it, but it doesn't work.                   
  //                        let newOne = ListOfDefinitions()
  //                        
  //                        
  //                        try! realm.write{
  //                            
  //                            realm.add(newOne)
  //                        }
  //                        self.newItemInStock.AverageCost = defJson["AverageCost"] as! Int
  //                        self.newItemInStock.Barcode = defJson["Barcode"] as! String
  //                        self.newItemInStock.Description = defJson["Description"] as! String
  //                        self.newItemInStock.InternalUnique = defJson["InternalUnique"] as! Int
  //                        self.newItemInStock.LastCost = defJson["LastCost"] as! Int
  //                        self.newItemInStock.LimitToMainRegionUnique = defJson["LimitToMainRegionUnique"] as! Int
  //                        self.newItemInStock.Notes = defJson["Notes"] as! String
  //                        self.newItemInStock.StockCategoryUnique = defJson["StockCategoryUnique"] as! Int
  //                        self.newItemInStock.StockCode = defJson["StockCode"] as! String
  //                        self.newItemInStock.StockGroupUnique = defJson["StockGroupUnique"] as! Int
  //                        self.newItemInStock.UnitDescriptor = defJson["UnitDescriptor"] as! String
  //                        
  //                        try! realm.write{
  //                            
  //                            self.newItemInStockList.listOfItems.append(self.newItemInStock)
  //                        }
  
                  }
  
              case .Failure(let error):
                  print("Request failed with error: \(error)")
              }
  </code></pre>
  
  <p>And here is what I get when I print the 4 Arrays</p>
  
  <p><a href="https://i.stack.imgur.com/U6RfT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U6RfT.png" alt="enter image description here"></a></p>