【发布时间】:2014-02-05 03:48:56
【问题描述】:
我正在通过核心数据将新对象插入数据库。在我插入值之前,有什么方法可以检查数据库中是否有任何重复项?
AccountDetails * newEntry = [NSEntityDescription insertNewObjectForEntityForName:@"AccountDetails" inManagedObjectContext:self.managedObjectContext];
newEntry.acc_date=date;
newEntry.bank_id=bank_id1;
NSError *error;
if (![self.managedObjectContext save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
[self.view endEditing:YES];
每次我运行应用程序时,它都会重新插入值。我想检查其中是否有任何新类别,如果没有,那么我将只添加该新类别。
提前谢谢..
【问题讨论】:
-
在插入之前进行提取。仅当获取计数为 0 时才插入。
标签: ios iphone core-data ios7 core-data-migration