iOS:使用对象更新核心数据DB

时间:2014-05-05 16:55:06

标签: ios core-data nsfetchrequest

我有这个cose来更新我的实体:

for (id element in array){

    Locality *locality = [NSEntityDescription insertNewObjectForEntityForName:@"Locality" inManagedObjectContext:temporaryContext];

    locality.name = [element objectForKey:@"n"];
    locality.id_locality = [element objectForKey:@"id"];


    NSFetchRequest *fetc_reg = [NSFetchRequest fetchRequestWithEntityName:@"Region"];
    [fetc_reg setPredicate:[NSPredicate predicateWithFormat:@"id_region = %@",[element objectForKey:@"r"]]];
    [fetc_reg setIncludesPropertyValues:NO];
    Region *region = [[temporaryContext executeFetchRequest:fetc_reg error:&error]lastObject];
    locality.region = region;
}

正如您所看到的,我创建了一个名为locality的新实体,它与region具有关系,因此我为locality设置了region。 我注意到如果我这样做NSFetchRequest它的内存非常昂贵,因为我有大约15000个地方,有没有一种快速的方法来在地方添加与地区的关系?

0 个答案:

没有答案