-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
6952
-
Needed
-
Please add information to this field.
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
- is cloned by
-
RCOCOA-1508 Implement writeAsync for Swift
- Closed