views:

18

answers:

1

In the FRC documentation, it says that it is intended to efficiently manage the results returned from a Core Data fetch request to provide data for a UITableView object.

I am trying to setup my Core Data stack to handle the storage and retrieval of some VERY basic data. Can I not use FRC? I need to display a value set in the db to a UILabel, what is the best Core Data method to use for that?

I have a core data book I am trying to get through, but the going is rough, so any help here would go a long way. Thanks!!

A: 

NSFetchedResultsController may be overkill if all you want is to fetch an object and display one of its attributes in UILabel. Take a look at NSFetchRequest and start with something like this:

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:entityDescription
                         inManagedObjectContext:managedObjectContext]];

NSPredicate *predicate = /* define predicate here */;
[fetchReqest setPredicate:predicate];

NSError *error = nil;
NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];

If you want to sort your results, read up on NSSortDescriptor. You will need to set sort descriptors prior to -executeFetchRequest: call.

Your results will be in 'results' array - and they should include NSManagedObjects that you can get attribute values from.

westsider