在我的应用程序中,我有以下代码来更新数据库:
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest=[NSFetchRequest fetchRequestWithEntityName:@"Struct"];
NSError *error = nil;
for (id element in array){
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"id==%@",[element objectForKey:@"id"]]];
Struct *struct = [[context executeFetchRequest:fetchRequest error:&error] lastObject];
if (struct != nil){
//updating value of attributes
struct.name = [element objectForKey:@"n"];
struct.val = [element objectForKey:@"val"];
struct.pos = [element objectForKey:@"pos"];
}
else{
//create a new identity
}
}
没关系,但我还有其他两个与 Struct 相关的对象:
“Id_Loc”(一对多)“Details”(一对一)
我不知道如何更新它们,我不知道如何从我的对象“结构”中调用它们我什么也没找到你能帮帮我吗?谢谢