如何将此数组加载到核心数据实体中?
您好,我正在努力弄清楚如何循环下面的数组并将每一行添加到我的核心数据实体中,
任何帮助将不胜感激,
//CREATE AN ARRAY FROM CSV DOCUMENT USING CHCSVPARSER
NSError *error;
NSString *customerCSV = [[NSBundle mainBundle] pathForResource:@"CUSTOMERS" ofType:@"csv"];
NSArray *importArray = [NSArray arrayWithContentsOfCSVFile:customerCSV encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@",importArray);
//LOOP THROUGH CREATED ARRAY AND ADD OBJECTS TO COREDATA CUSTOMER ENTITY
Invoice_MarketAppDelegate* delegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext* managedObjectContext = delegate.managedObjectContext;
NSManagedObject* newCustomer;
newCustomer = [NSEntityDescription insertNewObjectForEntityForName:@"Customers" inManagedObjectContext:managedObjectContext];
我不知道在这里该怎么做。
for () {
NSLog(@"importing Row");
}
这是我将导入的属性的日志,
NSLog(@"%@",importArray);
由于 csv 包含列名称,因此在命令中提供
(
CONTACTNAME,
PHONE,
COMPANYNAME,
NOTES
),
Hi I am struggling to figure out how to loop through the array below and add each row into my core data entity
Any help would be greatly appreciated
//CREATE AN ARRAY FROM CSV DOCUMENT USING CHCSVPARSER
NSError *error;
NSString *customerCSV = [[NSBundle mainBundle] pathForResource:@"CUSTOMERS" ofType:@"csv"];
NSArray *importArray = [NSArray arrayWithContentsOfCSVFile:customerCSV encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@",importArray);
//LOOP THROUGH CREATED ARRAY AND ADD OBJECTS TO COREDATA CUSTOMER ENTITY
Invoice_MarketAppDelegate* delegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext* managedObjectContext = delegate.managedObjectContext;
NSManagedObject* newCustomer;
newCustomer = [NSEntityDescription insertNewObjectForEntityForName:@"Customers" inManagedObjectContext:managedObjectContext];
I don't know what to do here.
for () {
NSLog(@"importing Row");
}
Here is a log of the attributes I will be importing, provided at the command
NSLog(@"%@",importArray);
since the csv included column names
(
CONTACTNAME,
PHONE,
COMPANYNAME,
NOTES
),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你只有 4 个对象,那么不必费心循环,你可以简单地 -
如果你有一个 Customers 子类,你可以使用:
否则你将需要使用
BUT
如果你有很多属性CSV,您可以在实体中设置其他键数组,并且 -
有时更好
处理此问题的更好方法,尤其是如果您有很多属性,则可以使用 -
编辑
要对实体进行子类化:
顺便说一句
If all you have is 4 objects, don't bother looping you can simply -
If you have a sub class of Customers you can use:
else you will need to use
BUT
If you have many properties in your CSV you can set an other array of the keys in your entity and -
Better sometimes
A better way to handle this, ecpaciely if you have many properties is to use -
EDIT
To sub class your entity:
BTW