将CSV加载到Core Data managed sqlite db [英] Loading a CSV into Core Data managed sqlite db
问题描述
我有一个包含数据的CSV文件。
我想把它加载到一个核心数据管理的sqlite db。
我只是运行了一个示例Core Data Xcode应用程序,并注意到它创建了db文件。
我注意到,表名称都以Z开头,主键存储在单独的表中,所以从我这是我正确的是,只是使用sqlite3命令行直接导入CSV数据到db可能会搞乱主键。 / p>
我需要编写一个程序来逐行读取CSV,然后为每一行创建对象,并将它们持久化到db。
任何人都有这个代码吗?
我可以写一个桌面客户端使用Core Data。如果是这样,那么db可以很好地用于IPhone核心数据应用程序?
然后我可以在我的项目中包含预填充的数据库,它将与应用程序正确部署
使用 NSScanner
将您的CSV文件读入 NSManagedObject
实例。
I have a CSV file containing data. I want to load it into a Core Data managed sqlite db.
I just ran one of the sample Core Data Xcode apps and noticed it created the db file. I noticed table names all started with Z and the primary keys were stored in separate table so from this am I right in presuming that just importing the CSV data directly into the db using sqlite3 command line might mess up primary keys.
Do I need to write a program to read in the CSV line by line and then create objects for each row and persist them to the db. Anyone got any code for this? And can I write a desktop client to do this using Core Data. If so will the db be fine to use in IPhone core data app?
Can I then just include the prefilled db in my project and it will be deployed with the app correctly or is there something else I should do.
Use NSScanner
to read your CSV file into the NSManagedObject
instances in your Core Data store.
这篇关于将CSV加载到Core Data managed sqlite db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!