简体   繁体   中英

Core Data import at first app launch

I have a problem with my data import at my app launch. At first launch, I create a lot of core data objects (almost 400 objects). The problem is, when I try the app in simulator, all seems to be right but on a device, I have to wait a lot of time because of my importation and maybe, the app crash (not everytime).

Is someone ever had this problem ? Should I try to make my importation script more efficient ? Is some good practices about data importation with Core Data exists ?

Thanks a lot in advance !

I usually use the same technique as Gopal. Other than file size, the only downside I've hit is is you find errors in shipped data. If that happens and you need to fix the data, you need to determine if the bad data exists in the user data and update it. I dealt with this at launch by checking a didUpdateToVersionX value in the NSUserDefaults for the app, querying the user data store to find the erroneous records, updating the relevant objects, saving the store, and setting the preference flag.

Is your seed data meant to be user-editable or read-only? If it's read-only, you should be able to have separate read-only and user-writable stores (the former in the app bundle, the latter in the Documents directory). Marcus Zarra's did a nice writeup of this technique in response to another question. Depending on your setup, it might involve a little extra work. I wanted to switch the aforementioned app over to using this technique, but I never had the chance.

I normally bundle the sqlite file which has the initial data in the app itself. On app launch, check if the db file exists, if not copy it from the bundle to the documents directory or wherever.

Faster launch times at the cost of increased app size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM