gpt4 book ai didi

ios - 根据核心数据实体的两个属性删除对象

转载 作者:行者123 更新时间:2023-11-29 03:18:56 24 4
gpt4 key购买 nike

在我的应用程序中,如果两个属性值等于字符串变量,我需要删除核心数据对象。这必须通过按钮操作来完成。如何确定要删除的对象?

最佳答案

 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];
}

关于ios - 根据核心数据实体的两个属性删除对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21358730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com