I want to save the large amount of data into CoreData, The resource of my Data is in CSV format.
I know the following ways to achieve it.
- With Help of Multiple MOC - I already tried with this one but its only help me to not freeze the my app on Main thread, Actually after the splash I want to use that data as well and while data is being save at background thread - Chances to not have that data immediately on required screen(Actually even I faced it, I was not able to fetch entity I want - Perhaps still its remaining to save on CoreData stack?)
- Do I need to convert that file into plist extension file? Is that the good idea to store large amount of data in plist file? And unfortunately I was not able to find any online tool which converts my .csv file to .plist file? I guess reading the data from plist is not a big deal.
Preloaded database need to be import into CoreData, Right now I am working by this way, I successfully converted my CSV file to SQLite file and imported it to bundle and then copy it from the bundle to Document Directory while NSPersistentContainer will be initialize. Now I have some few queries on this point as below.
- I found the SQLite file inside Document Directory, But its actually just copy the Existing SQLite's Tables with My CoreData Entities, What I want is that One of Table from Existing SQLite should be merge with My CoreData Entity, Do I need to loop over the table for each row and then manually save it to Entity? If so then its the same situation as I mentioned at Point 1.?
- Somewhere I found that CoreData DB structure and SQLite DB structure are different, so What I did - I created some Dummy Data on CoreData and Found the SQLite file, Inside that SQLite file I imported the data from CSV Table and now That SQLite file I have used in application bundle, I guess here I achieved something as I got an error says migration Failed as Table already exist on Database, Don't I need to define Entity first into DataModel?, OR Don't I need to Create the table inside SQLite File?(If so then Where I can pre-populate the Data?)
Please suggest What I Need to Do? And how can I achieve it? Also It would be great if you suggest any other options to Do so.