realm-swift icon indicating copy to clipboard operation
realm-swift copied to clipboard

Request: RealmConfiguration should have initial data transaction option

Open dhiraj opened this issue 8 years ago • 4 comments

Goals

Realm-Java has a very nice method in RealmConfiguration which lets me set up an "initial" data transaction, where I can add all the objects that I need, it is only triggered the first time that I access the realm instance, and never after that.

Expected Results

Realm-Cocoa should also have this option in RealmConfiguration so that we can set up code based initial data population, instead of having to depend on a separate, bundled Realm database.

dhiraj avatar Jul 15 '16 08:07 dhiraj

Thanks a lot for the suggestion @dhiraj! I've added this to our backlog so we can review it later. :)

TimOliver avatar Jul 15 '16 16:07 TimOliver

Since RLMRealm has an isEmpty property, I don't see us adding this any time soon since it's just as easy to use that to accomplish what you'd like.

jpsim avatar Jul 26 '16 18:07 jpsim

@jpsim I'm not sure isEmpty is a total replacement for this feature. Imagine an app that launches populated sample data (by checking isEmpty). If the user deletes all the sample data and relaunches the app, it will again be repopulated with sample data.

That said, it's still possible to accomplish the desired effect by inserting some singleton state object after first launch, though this is a bit more tricky for users.

JadenGeller avatar Jul 26 '16 18:07 JadenGeller

True. There's also the matter of requiring an inter-process lock to avoid race conditions, I just don't think this should be prioritized higher than it is now is all.

jpsim avatar Jul 26 '16 18:07 jpsim