Reputation: 20975
I'm migrating from CoreData to Realm... essentially i need to have two separate databases, lets say one with In-Memory only and the second one with Disc persistence
Now during parsing, i need create a Realm which can work in the given thread but be linked with the top Realm of my choice, not only the default Realm (like a CoreData child context for a thread)
Currently i do this like
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
RLMRealm * realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
// ...
[realm commitWriteTransaction];
dispatch_async(dispatch_get_main_queue(), ^{
// the objects from above are now saved in the default real
});
});
But i need to have 2 main Realms (one in memory and one disc stored), and than do smth like
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
RLMRealm * realm = [RLMRealm childRealmWithParentRealm:myRealm1];
[realm beginWriteTransaction];
// ...
[realm commitWriteTransaction];
dispatch_async(dispatch_get_main_queue(), ^{
// the objects from above are now saved in the myRealm1
});
});
Upvotes: 1
Views: 338
Reputation: 15991
This sounds like you might be trying to over-engineer a solution when you don't really need it.
Realm doesn't subscribe to the same model as Core Data where you need a chain of contexts to ensure everything is updated across threads. Once a write transaction has been committed, the changes to that Realm are available on all threads on the next iteration of the run loop.
My recommendation would be to remove the in-memory Realm (even just temporarily), do everything with the on-disk Realm and see if that works sufficiently for your needs. Realm is wicked fast, so you shouldn't really need an in-memory buffer version like that.
If you absolutely do need an in-memory Realm, keep in mind that they will be two discrete Realm entities; you cannot link them, and you cannot share objects between them (You'll need to manually create them for each Realm), so you should evaluate if you really need it. Good luck!
Upvotes: 1