magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

Is it safe to initialise MR on a background thread? #1200

Open chrisjenkins opened 8 years ago

chrisjenkins commented 8 years ago

Hi, I am wondering if it is safe to initialise MR 2.3.2 on a background thread? Specifically all I want to do is call:

[MagicalRecord setShouldDeleteStoreOnModelMismatch:NO]; [MagicalRecord setDefaultModelNamed:@"Model.momd"]; [MagicalRecord setupAutoMigratingCoreDataStack];

And then return to the main thread for UI access as normal, this is in case migration takes a long time.

Many thanks.

danielgalasko commented 8 years ago

This depends on your usage but you must understand that if you are setting up in the background then your UI cannot be dependent on Magical Record at least until it finishes...

So basically if you don't need MR on the main thread during your launch and first screens and any screens that do need MR can wait then you should be good. My bet is that its safest to block the main thread for you...

How expensive is migration in your case? You might be better off showing a spinner or some kind of progress bar during migration and then perform setup in the background...