Uploaded image for project: 'Realm Cocoa SDK'
  1. Realm Cocoa SDK
  2. RCOCOA-1508

Implement writeAsync for Swift

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • Q1-23FY
    • Affects Version/s: None
    • Component/s: None

      Right now doing your commits on a background thread is quite a complicated affair. You have to open a new realm there, remember to close it again unless you end up pinning the realm, and if you need to bring objects along from the parent (often UI) thread, you have to either pass a primary key and do lookups to retrieve the same object(s) in the new thread (which does not work for lists and query results), or you have to use our handover mechanics which involve multiple steps and is largely undocumented.

      It would hugely increase the usability if we had a simple method that did the commit for you in the background and also allowed you to handover objects and collections (live or frozen) to the the background task:

      // do a query on the local thread
      let readEmails = realm.objects(Email.self).filter("read == true")
      
      // delete all objects in the query result on a background thread
      realm.writeAsync(readEmails) { (realm, readEmails) in
          realm.delete(readEmails)
      }
      

      This old recipe describes the problem in detail, with an example showing the amount of code a user have to write to do it themselves: https://docs.mongodb.com/realm-legacy/docs/cookbook/swift/object-to-background.html

            Assignee:
            pavel.yakimenko@mongodb.com Pavel Yakimenko (Inactive)
            Reporter:
            pavel.yakimenko@mongodb.com Pavel Yakimenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: