0

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]];
}
matteodv
  • 3,992
  • 5
  • 39
  • 73

1 Answers1

1

Why not just say something like [[myShop employees] count]?

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • You're passing an NSUInteger value to a format string that's expecting an object. Change that `%@` to `%d` and you should be fine. – Lily Ballard Sep 07 '11 at 23:10
  • Thank you so much! Worked fine ;) It seems to be a big problem but the answers is so simple XD – matteodv Sep 07 '11 at 23:14