I've used the CoreDataBooks as a model for this app, and have run into a problem in that that sample uses 1 table and I need to use two. (Verbs and Persons).
Here is part of my code in the rootController.m file:
// Create and configure a fetch request with the Verb entity.
NSFetchRequest *fetchRequestVerb = [[NSFetchRequest alloc] init];
NSEntityDescription *verbEntity = [NSEntityDescription entityForName:@"Verb" inManagedObjectContext:managedObjectContext];
[fetchRequestVerb setEntity:verbEntity];
// Create the sort descriptors array.
NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSSortDescriptor *typeDescriptor = [[NSSortDescriptor alloc] initWithKey:@"type" ascending:YES];
NSSortDescriptor *translationDescriptor = [[NSSortDescriptor alloc] initWithKey:@"translation" ascending:YES];
NSSortDescriptor *presentDescriptor = [[NSSortDescriptor alloc] initWithKey:@"present" ascending:YES];
NSSortDescriptor *simpPastDescriptor = [[NSSortDescriptor alloc] initWithKey:@"simplePast" ascending:YES];
NSSortDescriptor *contPastDescriptor = [[NSSortDescriptor alloc] initWithKey:@"contPast" ascending:YES];
NSSortDescriptor *simpFutureDescriptor = [[NSSortDescriptor alloc] initWithKey:@"simpleFuture" ascending:YES];
NSSortDescriptor *contFutureDescriptor = [[NSSortDescriptor alloc] initWithKey:@"contFuture" ascending:YES];
NSSortDescriptor *imperativeDescriptor = [[NSSortDescriptor alloc] initWithKey:@"imperative" ascending:YES];
// RETRIEVE from PERSONS table...
NSSortDescriptor *single1Descriptor = [[NSSortDescriptor alloc] initWithKey:@"single1" ascending:YES];
NSSortDescriptor *single2Descriptor = [[NSSortDescriptor alloc] initWithKey:@"single2" ascending:YES];
NSSortDescriptor *single3Descriptor = [[NSSortDescriptor alloc] initWithKey:@"single3" ascending:YES];
NSSortDescriptor *plural1Descriptor = [[NSSortDescriptor alloc] initWithKey:@"plural1" ascending:YES];
NSSortDescriptor *plural2Descriptor = [[NSSortDescriptor alloc] initWithKey:@"plural2" ascending:YES];
NSSortDescriptor *plural3Descriptor = [[NSSortDescriptor alloc] initWithKey:@"plural3" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:
nameDescriptor,
typeDescriptor,
translationDescriptor,
presentDescriptor,
simpPastDescriptor,
contPastDescriptor,
simpFutureDescriptor,
contFutureDescriptor,
imperativeDescriptor,
single1Descriptor,
single2Descriptor,
single3Descriptor,
plural1Descriptor,
plural2Descriptor,
plural3Descriptor,
nil];
[fetchRequestVerb setSortDescriptors:sortDescriptors];
// Create and initialize the fetch results controller.
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequestVerb managedObjectContext:managedObjectContext sectionNameKeyPath:@"name" cacheName:@"Root"];
self.fetchedResultsController = aFetchedResultsController;
fetchedResultsController.delegate = self;
and my data model is attached.
Of course, when I try to access the first item from the Persons table, I get an exception.. Should I make an additional viewController? Should I have another fetch routine in the vc that accesses the Persons table? Am I doing the whole thing wrong?
David