How to do Core Data queries through a relationship?

前端 未结 2 1668
灰色年华
灰色年华 2021-01-31 12:53

I\'m messing around with Core Data, and I am sure I am missing something obvious, because I cannot find an example that at all resembles what I am trying to do.

Let\'s s

2条回答
  •  暖寄归人
    2021-01-31 13:15

    Or you can use another predicate:

    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Actor" inManagedObjectContext:self.managedObjectContext];
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name = %@",@"Chuck Norris"]
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:entity];
    [request setPredicate:predicate];
    
    YourActorObject *chuck = [[self.managedObjectContext executeFetchRequest:request error:nil] objectAtIndex:0];
    [request release];
    
    NSSet *moviesWithChuck = chuck.movies;
    

提交回复
热议问题