我想将数据保存在核心数据中。
但保存的数据是唯一的最后数据。
我认为,重要的问题是唯一的!只要!保存最后一个数据。
其实我英文不太好...
请我想让你明白我的问题..
这是我的代码。
正如我解释这段代码。这个项目有一个样本。csv,所以我将该文件分开。并且分离的数据由“setvalue”保存。
这是什么问题??
NSString *path = [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"csv"];
NSString *strText = [NSString stringWithContentsOfFile:path encoding:NSEUCKREncoding error:nil];
NSArray * array = [strText componentsSeparatedByString:@"\n"];
NSString *tempText;
int i = 0;
NSArray * temparray;
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
NSManagedObjectContext *newContext = [appDelegate managedObjectContext];
NSManagedObject *newContact;
newContact = [NSEntityDescription insertNewObjectForEntityForName:@"Contacts" inManagedObjectContext:newContext];
NSError *error;
for(i = 1;i<[array count]-1;i++){
tempText = [[array objectAtIndex:i]description];
temparray = [tempText componentsSeparatedByString:@"##"];
[newContact setValue:[temparray objectAtIndex:0] forKey:@"name"];
[newContact setValue:[temparray objectAtIndex:1] forKey:@"phone"];
[newContact setValue:[temparray objectAtIndex:2] forKey:@"sex"];
[newContext save:&error];
}