I have to entity, A and B (A <<---> B) so an A object can have one B object and a B object can have more than one A object (Correct me if I'm wrong, I'm new to core data relationships).
Now, I want to know how many A objects are in a B object. For example I have a shop (employee <<---> shop) and I want to know how many employee work in that shop.
I've create something like this without success:
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Task" inManagedObjectContext:self.managedObjectContext];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"project == %@", aProject];
[request setPredicate:predicate];
NSError *error = nil;
NSInteger resultNumber = [self.managedObjectContext countForFetchRequest:request error:&error];
if (!resultNumber) {
NSLog(@"Risultati della richiesta nulli!");
abort();
}
NSLog(@"getCountOfProjects called");
NSLog(@"Results: %@", resultNumber);
return resultNumber;
Can you help me? Than you so much! ;)
Update
I've tried to use this code but it doesn't work...
-(void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
Project *projects = (Project *)[fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = projects.title;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ entries", [projects.task count]];
}