Skip to content

Instantly share code, notes, and snippets.

@thekarladam
Created July 20, 2011 21:09
Show Gist options
  • Save thekarladam/1095943 to your computer and use it in GitHub Desktop.
Save thekarladam/1095943 to your computer and use it in GitHub Desktop.
[A, A->B, A->C] => {A & B} & {A & C}
NSManagedObject *itemA = [NSEntityDescription insertNewObjectForEntityForName:@"Group" inManagedObjectContext:self.managedObjectContext];
NSManagedObject *itemB = [NSEntityDescription insertNewObjectForEntityForName:@"Subgroup" inManagedObjectContext:self.managedObjectContext];
NSManagedObject *itemC = [NSEntityDescription insertNewObjectForEntityForName:@"Folder" inManagedObjectContext:self.managedObjectContext];
NSFetchRequest *aAndBFetch = [[NSFetchRequest alloc] initWithEntityName:@"Group"];
NSFetchRequest *aAndCFetch = [[NSFetchRequest alloc] initWithEntityName:@"Group"];
[aAndBFetch setIncludesSubentities:YES];
[aAndCFetch setIncludesSubentities:YES];
[aAndBFetch setPredicate:[NSPredicate predicateWithFormat:@"entity.name == \"Group\" OR entity.name == \"Subgroup\""]];
[aAndCFetch setPredicate:[NSPredicate predicateWithFormat:@"entity.name == \"Group\" OR entity.name == \"Folder\""]];
NSArray *aAndB = [self.managedObjectContext executeFetchRequest:aAndBFetch error:nil];
NSArray *aAndC = [self.managedObjectContext executeFetchRequest:aAndCFetch error:nil];
NSLog(@"aAndB: %@", aAndB);
NSLog(@"aAndC: %@", aAndC);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment