Hi,
I have a Core Data based iPhone application that needs to save 1000 managed objects on termination. This takes 8+ seconds, however, the OS kills the app if it does not complete in approx. 6 seconds.
I don't want to save the objects earlier, because then the user has to wait 8 seconds longer for the results to display.
Is it possible to somehow save the objects earlier in a background thread, while still having (read-only) access to the NSManagedObjectContext in the main thread to display the data? Or is it somehow possible to duplicate the managed objects, and pass the duplicates to a background thread for saving?
For clarification, here is what happens in the application now: I have a background thread that imports 1000+ objects in about 1 sec. If I save while importing, it takes a lot longer than 1 sec. So in order to display those items with minimum delay, the context is handed off without saving to the main thread, and the user gets his results as fast as possible.
I now have the problem how to save these objects without the user having to wait the 8 secs. If I save in the background thread before handing over, the user has to wait. If I save in the foreground thread after handing over, the user has to wait. The only two possible approaches I can see right now are:
- Somehow having core data doing its sqlite accesses in the background, while still keeping the main thread reactive
- Handing the objects unsaved from one context to another, and saving in the background thread
Both approaches seem impossible (at least according to the Core Data documentation). So is there no other solution than to have the user wait longer (and maybe display a nice rotating hour glass :-)?
Regards, Jochen