Amazon.com Widgets CoreData Question - trying to access data from two tables.
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2013, 06:36:07 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  iOS Programming
| |-+  General Questions
| | |-+  CoreData Question - trying to access data from two tables.
Pages: [1]   Go Down
Print
Author Topic: CoreData Question - trying to access data from two tables.  (Read 716 times)
daviddelmonte
Full Member
***
Posts: 123



WWW Email




« on: December 17, 2010, 06:44:12 PM »

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:

Code: (Objective-C)
// 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


Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.