Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing large datasets on iPhone using CoreData

I'm facing very annoying problem. My iPhone app is loading it's data from a network server. Data are sent as plist and when parsed, it neeeds to be stored to SQLite db using CoreData.

Issue is that in some cases those datasets are too big (5000+ records) and import takes way too long. More on that, when iPhone tries to suspend the screen, Watchdog kills the app because it's still processing the import and does not respond up to 5 seconds, so import is never finished.

I used all recommended techniques according to article "Efficiently Importing Data" http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/CoreData/Articles/cdImporting.html and other docs concerning this, but it's still awfully slow.

Solution I'm looking for is to let app suspend, but let import run in behind (better one) or to prevent attempts to suspend the app at all. Or any better idea is welcomed too.

Any tips on how to overcome these issues are highly appreciated! Thanks

like image 867
Matthes Avatar asked Jan 26 '10 16:01

Matthes


1 Answers

Instead of pushing plist files to the phone, you might want to send ready to use sqlite files. This has many advantages:

  1. no need to import on the phone
  2. more compact

If you always replace the whole content simply overwrite the persistent store in the device. Otherwise you may want to maintain an array as plist with all sqlites you have downloaded and then use this to add all stores to the persistentStoreCoordinator.

Bottom line: use several precompiled sqlite files and add them to the persistentStoreCoordinator.

You can use the iPhone Simulator to create those CoreData-SQLite-Stores or use a standalone Mac app. You will need to write both of those yourself.

like image 100
Felix Lamouroux Avatar answered Oct 01 '22 20:10

Felix Lamouroux