title: Attempting to create an object of type 'Item' with an existing primary key value '1'
body: <p>I have three classes, <code>Folder</code>, <code>Object</code> &amp; <code>Item</code>. </p>
  
  <p>For every <code>Folder</code> there are a list of <code>objects</code>, and for every <code>Object</code> there should be a list of <code>items</code>. However when creating an <code>Object</code> with a default list of <code>items</code> I am getting the following error; </p>
  
  <blockquote>
    <p>*** Terminating app due to uncaught exception 'RLMException', reason: 'Attempting to create an object of type 'Item' with an existing
    primary key value '1'.'</p>
  </blockquote>
  
  <p>For each class I have a function that counts all the objects and increments the ID, this works fine but there must be something wrong with how I am adding <code>Item</code> to an <code>Object.items</code> list property. </p>
  
  <p><strong>Item</strong></p>
  
  <pre><code>class Item: Object {
  
  @objc dynamic var id: Int = 0
  @objc dynamic var object: Object?
  
  @objc dynamic var title: String = ""
  
  override static func primaryKey() -&gt; String? {
      return "id"
  }
  
  func IncrementaID() -&gt; Int{
      let realm = try! Realm()
  
      var num = 1
  
      let allItems = realm.objects(Milestone.self)
      if allItems.count &gt;= 1 {
          num = allItems.count + 1
      }
  
      return num
  }
  
  
  }
  </code></pre>
  
  <p>When creating an <code>Object</code> I am also trying creates <code>Item</code>'s to append to the objects <code>items</code> property like so</p>
  
  <pre><code> func addObjectToFolder(_ title: String, folder: Folder) {
  
  
      let object = Object()
  
      object = object.IncrementaID()
  
      object.title = title
  
  
      let defaultList = ["1", "2", "3", "4", "5"]
  
      for i in defaultList {
  
          let item = Item()
  
          item.id = item.IncrementaID()
  
          item.title = i
  
          object.items.append(item)
      }
  
      try! realm.write {
          folder.objects.append(object)
      }
  
  }
  </code></pre>
  
  <p>Does an body know how I am going wrong when creating the default values for the <code>Objects.items</code> list ? </p>