我有一个这样的数组列表:
(
"08-12-2016, Thursday, Greg",
"15-12-2016, Thursday, Greg",
"22-12-2016, Thursday, Greg",
"08-12-2016, Thursday, tug"
)
此数组列出了如何使用coredata
在DataBase表中重新加载我想在数据库表中重新加载此数据
我该怎么办?我经常尝试多次,但不在DataBase表中插入数组数据。请帮忙
答案 0 :(得分:0)
long int counts=[resultss count];// resultss is a array list
for(int i=0;i<counts;i++)
{
NSArray*foos = [[resultss objectAtIndex:i] componentsSeparatedByString:@","];
NSString*date_name = [foos objectAtIndex:0];
NSString*day_name = [foos objectAtIndex:1];
NSString*name_name = [foos objectAtIndex:2];
NSLog(@"date_name %@",date_name);
NSLog(@"day_name %@",day_name);
NSLog(@"name_name %@",name_name);
//new device
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"Cal" inManagedObjectContext:context];
[newDevice setValue:date_name forKey:@"date"];
[newDevice setValue:day_name forKey:@"day"];
[newDevice setValue:name_name forKey:@"pillname"];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
}