title: How get Realm result of objects in background queue, then use it on main thread
body: <p>I'm new in Realm. I have db Reaml and show some data from db to Tableview.</p>
  
  <p>My code:</p>
  
  <pre><code>class MyRealmObject: Object {
  @objc dynamic var id = 0
  @objc dynamic var name = ""
  @objc dynamic var favorite = false}
  
  class MyViewController: UIViewController, ... {
      let realm = try! Realm()
      var objectsResult: Results&lt;MyRealmObject&gt;!
      ...
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
  
      cell.textLabel?.text = objectsResult[indexPath.row].name
      ...
  
      return cell
  }
  
  func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
      //searching block
      ...
      DispatchQueue.global().async {
          autoreleasepool{
              let realm = try! Realm()
              var newObjectsResult: Results&lt; MyRealmObject&gt;!
              newObjectsResult = realm.objects(Objects.self).sorted(byKeyPath: "name", ascending: true).filter("name beginswith[cd] %@", searchText)
              objectsResult = newObjectsResult
              DispatchQueue.main.async {
                  self.tableView.reloadData()
              }
          }
      }
  
  }
  </code></pre>
  
  <p>In this case I got this error:</p>
  
  <pre><code>2018-09-22 14:42:48.262734+0800 TestApp[1194:338211] *** Terminating app due to uncaught exception 'RLMException', reason: 'Realm accessed from incorrect thread.'
  </code></pre>
  
  <p>How I can use realm objects from background thread to main thread for reloading my tableview?</p>