title: Realm Collection Insertion for UI Update
body: <p>If you look at the Realm docs for Swift, the <a href="https://realm.io/docs/swift/latest/#interface-driven-writes" rel="nofollow noreferrer">Interface-driven Writes section</a> indicates that you can observe a <code>collection</code>:</p>
  
  <pre><code>// Add fine-grained notification block
  token = collection.observe { changes in
    switch changes {
  
    case .initial:
      tableView.reloadData()
  
    case .update(_, let deletions, let insertions, let modifications):
      // Query results have changed, so apply them to the UITableView
      tableView.beginUpdates()
  
      // Always apply updates in the following order: deletions, insertions, then modifications.
      // Handling insertions before deletions may result in unexpected behavior.
      tableView.deleteRows(at: deletions.map({ IndexPath(row: $0, section: 0)}),
                            with: .automatic)
      tableView.insertRows(at: insertions.map({ IndexPath(row: $0, section: 0) }),
                            with: .automatic)
      tableView.reloadRows(at: modifications.map({ IndexPath(row: $0, section: 0) }),
                            with: .automatic)
      tableView.endUpdates()
  
    case .error(let error):
      // handle error
      ()
    }
  }
  </code></pre>
  
  <p>I assume this to mean the <code>collection</code> is of type <code>Results&lt;Item&gt;!</code>.</p>
  
  <p>But right below that, it demonstrates a way to perform a <code>write</code> while allowing the UI to update instantly:</p>
  
  <pre><code>func insertItem() throws {
    // Perform an interface-driven write on the main thread, making sure 
    // the change notification doesn't apply the change a second time
    try collection.realm!.write(withoutNotifying: [token]) {
      collection.insert(Item(), at: 0)
    }
  
    // And mirror it instantly in the UI instead
    tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
  }
  </code></pre>
  
  <p>But what doesn't make sense is that in this case, <code>collection</code> has an <code>insert</code> method which isn't available on a <code>Results&lt;Item&gt;!</code> type, only on an array.</p>
  
  <p>Is there a type that can be observed and inserted to? If not, do I just have to manage my own array and keep <code>Results&lt;Item&gt;!</code> in sync with my own <code>[Item]</code> array?</p>