简体   繁体   English

使用Swift从CSV初始化CoreData

[英]Using Swift to initialize CoreData from CSV

I have data in few CSV files which needs to be initialized in CoreData. 我有一些CSV文件中的数据,需要在CoreData中对其进行初始化。 I want to know if there is any way to initialize CoreData tables with CSV file data. 我想知道是否可以用CSV文件数据初始化CoreData表。

Thanks in Advance. 提前致谢。

Before going to the effort of storing your data in Core-Data I would first think about what are you using the data for? 在努力将数据存储在Core-Data中之前,我首先会考虑您将数据用于什么目的? how big is it, etc. 它有多大,等等。

If you are doing some simple reading from the csv file and the data is not large, then maybe it is not necessary to store in core-data. 如果您正在从csv文件中进行一些简单的读取并且数据不大,则可能没有必要存储在核心数据中。

If go down the core-data route, then you need to create the data models before you perform an import. 如果沿着核心数据路线走,那么您需要在执行导入之前创建数据模型。 So you are going to have to create tables and fields with the correct data types. 因此,您将不得不使用正确的数据类型创建表和字段。 Once you have that in place, then you can create some code to read the csv file in and then parse the data and create new instances of core data records to save and persist. 将其放置到位后,您可以创建一些代码以读取csv文件,然后解析数据并创建要保存和持久保存的核心数据记录的新实例。 My suggestion would be to use a library like Magical Record , which does a lot of the heavy lifting with core-data. 我的建议是使用像Magical Record这样的库,它对核心数据做了很多繁重的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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