Reputation: 16128
I have an app using coreData fine.
I have this relationship:
company <--->> visitors
now, I need to find specific visitors for an specific company, I can fetch visitors starting with some string pattern,
But how to find the ones for a specific company?
here my code
- (void)searchAvailableDataFullName:(NSTimer*)timer
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"fullName BEGINSWITH [c] %@",self.nameTF.text];
//sort descriptor!
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"fullName" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
//the relationship of interest??
Visitor *theVisitor = nil;
theVisitor.company = self.selectedCompany;
NSMutableArray *fullNamesArray = [NSMutableArray arrayWithArray:[Visitor allWithPredicate:predicate sortDescriptors:@[sortDescriptor]]];
Visitor *visitorName;
NSMutableArray *dataArray = [NSMutableArray array];
for (visitorName in fullNamesArray) {
NSLog(@"tus visitors:: %@", visitorName.fullName);
[dataArray addObject:visitorName.fullName];
}
}
Upvotes: 0
Views: 84
Reputation: 362
I don't have my Mac in front of me atm but it should be something like:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"visitors.fullName BEGINSWITH [c] %@ && visitors.CompanyName BEGINSWITH [c] %@",self.nameTF.text, companyNameTextObject];
Hope that's 100% right, if not you can kind of get the gist of it. You can use the "table.relationshipProperty" to search the relationship.
Apple Predicate Programming Guide
There's some more info there, just check out the "Joins" section. Hope that helps!
Upvotes: 1