我读到了非常小心如何通过核心数据将许多行保存到表中的说明,但是它的工作错误。保存的值总是秒,并且有两个值。请帮我把错误发现到我的代码中:
-(void)saveDataToLocal{
NSManagedObject *newPref;
newPref = [NSEntityDescription insertNewObjectForEntityForName:@"Company" inManagedObjectContext:context];
[newPref setValue:@"SiliconPrime" forKey:@"name"];
[newPref setValue:@"Software company at VietNam" forKey:@"descreption"];
[newPref setValue:[NSNumber numberWithInt:3] forKey:@"rating"];
//
newPref = [NSEntityDescription insertNewObjectForEntityForName:@"Company" inManagedObjectContext:context];
[newPref setValue:@"Microsoft" forKey:@"name"];
[newPref setValue:@"USA Company" forKey:@"descreption"];
[newPref setValue:[NSNumber numberWithInt:3] forKey:@"rating"];
NSError *error;
if (![context save:&error]) {
NSLog(@"########## Error save data %@", [error localizedDescription]);
}
}
我将此功能调用到application didFinishLaunchingWithOptions:
。代码错误或我是否需要在xcdatamodeld文件或其他地方进行任何配置?
答案 0 :(得分:0)
你的意思是说只保存了第二个对象吗?第一个没有保存?您可以执行以下任一操作