在核心数据中,当删除实体的对象时,所有关系对象也会被删除,还有另一个实体详细信息具有一对多关系。我需要删除它的对象还是下面的代码来处理它?到目前为止我的代码:
NSFetchRequest * allClients = [[NSFetchRequest alloc] init];
[allClients setEntity:[NSEntityDescription entityForName:@"Client" inManagedObjectContext:[NSManagedObjectContext defaultContext]]];
[allClients setIncludesPropertyValues:NO]; //only fetch the managedObjectID
NSError * error = nil;
NSArray * clients = [[NSManagedObjectContext defaultContext] executeFetchRequest:allClients error:&error];
//error handling goes here
for (NSManagedObject * client in clients) {
[[NSManagedObjectContext defaultContext] deleteObject:client];
}
NSError *saveError = nil;
[[NSManagedObjectContext defaultContext] save:&saveError];
//more error handling here