0
在我的应用程序中,如果两个属性值等于字符串变量,我需要删除核心数据对象。这必须通过按钮操作完成。我应该如何确定要删除的对象?根据核心数据实体中的两个属性删除对象
在我的应用程序中,如果两个属性值等于字符串变量,我需要删除核心数据对象。这必须通过按钮操作完成。我应该如何确定要删除的对象?根据核心数据实体中的两个属性删除对象
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];
}
谢谢,我想它会工作... – mvasco