在我的应用程序中,如果两个属性值等于字符串变量,我需要删除核心数据对象。必须通过按钮操作完成。我该如何确定要删除的对象?
答案 0 :(得分:1)
NSEntityDescription *entity=[NSEntityDescription entityForName:@"entityName" inManagedObjectContext:context];
NSFetchRequest *fetch=[[NSFetchRequest alloc] init];
[fetch setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(value1 == %@) AND (value2 == %@)", data1, data2];
[fetch setPredicate:predicate];
//... add sorts if you want them
NSError *fetchError;
NSArray *fetchedData=[self.moc executeFetchRequest:fetch error:&fetchError];
for (NSManagedObject *product in fetchedProducts) {
[context deleteObject:product];
}