views:

27

answers:

0

hello my test application can currently load a table view which lists a couple of books, the detailview takes you to cells that displays the book text in cells. the user has the ability to bookmark a cell which is a boolean in the book_text table.

what i am trying to do is, on the main table view, is: 1-Load the books like how it does now 2-Add the number of of bookmarks next to the table name i've looked at the expression function that i could use in coredata but could not figure it out. below is my fetch request code.

the below SQL query can get me the count but i dont know how to do it in coredata

SELECT COUNT(*) as "textread" FROM Zbooktext WHERE ZBOOMARK = 'True';

   NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
      NSEntityDescription *book = [NSEntityDescription entityForName:@"book" inManagedObjectContext:self.managedObjectContext];
        [fetchRequest setEntity:book];
    [fetchRequest setFetchBatchSize:20];
     NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    [fetchRequest setSortDescriptors:sortDescriptors];
     NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
        aFetchedResultsController.delegate = self;
        self.fetchedResultsController = aFetchedResultsController;

        [aFetchedResultsController release];
        [fetchRequest release];
        [sortDescriptor release];
        [sortDescriptors release];

        NSError *error = nil;
        if (![fetchedResultsController_ performFetch:&error]) {
            NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
            abort();
        }

        return fetchedResultsController_;