You can write an NSPredicate against relationships just as you would against attributes.
For example:
- (BOOL)isPerson:(Person *)person memberOfNetwork:(Network *)network {
// assume NetworkMember entity is ivar networkMemberEntity_
// assume NSManagedObjectContext is ivar context_
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
[fetch setEntity:networkMemberEntity_];
[fetch setPredicate:[NSPredicate predicateWithFormat:
@"(person == %@) AND (networks CONTAINS %@)", person, network]];
[fetch setFetchLimit:1];
NSError *error = nil;
NSInteger count = [context_ countForFetchRequest:fetch error:&error];
if (count < 0) {
// always handle errors in real code
// and never check for errors using "error == nil"
}
return count > 0;
}
In the case you present, however, you should strongly consider whether you really need to do this. It sounds like you're trying to model a many-to-many relationship between Person and Network. If you come from a database background you might think you need a join table for this, and make an intermediate entity.
However, Core Data can manage all of that for you; you can create a many-to-many relationship directly between Person and Network and not have to maintain any intermediate entity or table yourself. Just like how you don't have to worry about primary and foreign keys when dealing with relationships in Core Data, the framework deals with that kind of thing for you, letting you work at the object level.