title: InMemory Realm Threading in Swift
body: <p>I'm trying to use in memory realm to store some objects. I usually <strong>save objects in a secondary thread</strong> and <strong>ask for objects on main thread</strong>.</p>
  
  <p>I also need to have a strong reference to the in memory Realm, in order to avoid data loss.</p>
  
  <pre><code>static private var _strongInMemoryRealm: Realm? = {
      return VideoObject._inMemoryRealm
  }()
  
  static private var _inMemoryRealm: Realm? {
      get {
  
          var realm: Realm? = nil
  
          let config = Realm.Configuration(inMemoryIdentifier: "InMemoryRealm")
  
          do {
              realm = try Realm(configuration: config)
          } catch let error {
              debugPrint("Realm could not be opened: ", error)
              Crashlytics.sharedInstance().recordError(error)
          }
  
          return realm
  
      }
  }
  </code></pre>
  
  <p>I call <strong>_inMemoryRealm</strong> in secondary threads and <strong>_strongInMemoryRealm</strong> on main thread, this configuration don't work. </p>