I am new to Core Data and i got stuck with a problem.
I have a file “db.sqlite” which has 3 tables and each containing around 10k records.
Now my question is can I add this file to my project and access(Select/Update) the data using CoreData API.
Thank You in advance.
You can’t use Core Data to read an arbitrary SQL file. Neither can you reliable convert an arbitrary SQL file into an SQL file that Core Data can use. The sqlite schema for Core Data is undocumented and ever changing. Core Data will only read and write its schema and each each sqlite store file must be configured to a specific data model file. Direct creation of a SQL store for Core Data is always a fragile solution.
It is important to understand that Core Data is not SQL. Entities are not tables. Objects are not rows. Attributes are not columns. Relationships are not joins. Core Data is an object graph management system that may or may not persist the object graph and may or may not use SQL far behind the scenes to do so. Trying to think of Core Data in SQL terms will cause you to completely misunderstand Core Data and result in much grief and wasted time.
As Mundi pointed out, you need to read the existing SQL file in using the standard SQL C API and then load that data in managed objects and have Core Data save the objects into its SQL store. It might sound like a lot of extra work but in reality you are translating from the limited SQL API which is concerned solely with getting data on and off disk to the Core Data API which provides a complete data model for your app.