title: Realm Server Object Incorrect Thread Exception
body: <p>I had an app were realm objects were managed locally like this</p>
  
  <pre><code>import Foundation
  import RealmSwift
  
  class Patient: Object {
  
      static var realm: Realm?
      dynamic var name = ""
  
      convenience init(name: String, save: Bool = false) {
          self.init()
          self.name = name
          if save() {
              self.save
          }
      }
  
  
      func save() {
          try! Patient.realm?.write {
              Patient.realm?.add(self, update: true)
          }
      }
  
      static func getAllPatients() -&gt; Results&lt;Patient&gt;? {
          return Patient.realm?.objects(Patient.self)
      }
  
  }
  </code></pre>
  
  <p>When I tried to convert the above code to sync with Realm Object Server, I got thread error trying to pass the realm instance passed from the login method to my class</p>
  
  <pre><code>static func userLogin(onCompletion: @escaping (Realm) -&gt; Void) {
      let serverURL = URL(string: "http://127.0.0.1:9080")!
      let credentials = SyncCredentials.usernamePassword(username: "test@test", password: "test")
      SyncUser.logIn(with: credentials, server: serverURL) {
          user, error in
  
          if let user = user {
              let syncServerURL = URL(string: "realm://localhost:9080/~/test")!
              let config = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: syncServerURL))
              let realm = try! Realm(configuration: config)
              onCompletion(realm)
          } else if _ = error {
          }
      }
  
  } 
  </code></pre>
  
  <p>and here to get the realm instance </p>
  
  <pre><code>userLogin() { realm in
          Patient.realm = realm
      }
  </code></pre>
  
  <p>Now, when I use this new <code>Patient.realm</code> in my class functions (<code>getAllPatients</code>), I get <code>incorrect thread exception</code></p>
  
  <p>Any possible way to pass the realm instance from userLogin to my class without causing this thread exception? If I put my queries in the login function, does that mean I need to login, sync everytime I need to get something from or edit the database?</p>