With the below code I'm creating a fetch request. The problem I'm having is getting the fetch request data and doing something with it like putting it into a variable (like I'm trying to do below with the firstManagedObject variable). I.e., I don't understand what to do with my "result" NSArray that I've created (shown in below code) to get usable data that isn't in the form of "(entity: Question; id: 0x10b6250 <-coredata://90FA9FD7-4CFC-4039-8A0C-40116055CADF/Question/p2 ; data: fault)" or similar. In the NSLog that I create (on the last line) I log the "result" NSArray filled from an executeFetchRequest (shown in bold below) but I don't know how to take the next step to get the actual "Question" text. Any help is appreciated. Thanks.
NSLog results:
fetch request getQuestionsByParent: 2 found (sub variables:{ formId = "9822217D-6A55-4475-88EC-E2552B336E1B"; sectionNumber = 2; }, results:( (entity: Question; id: 0x10a8720 x-coredata://90FA9FD7-4CFC-4039-8A0C-40116055CADF/Question/p2 ; data: fault), (entity: Question; id: 0x1092920 x-coredata://90FA9FD7-4CFC-4039-8A0C-40116055CADF/Question/p4 ; data: fault) ))
Code:
NSManagedObjectContext *moc_ = [self managedObjectContext];
NSMutableDictionary *dictionary=[[NSMutableDictionary alloc]init];
[dictionary setObject:section.ordinal forKey:@"sectionNumber"];
[dictionary setObject:section.parent.id forKey:@"formId"];
NSError *error = nil;
NSManagedObjectModel *model = [[moc_ persistentStoreCoordinator] managedObjectModel];
NSFetchRequest *fetchRequest = [model fetchRequestFromTemplateWithName:@"getQuestionsByParent" substitutionVariables:dictionary];
NSAssert(fetchRequest, @"Can't find question fetch request");
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"ordinal" ascending:YES];
NSArray *sortDescriptors = [[NSMutableArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSArray *result = [[NSArray alloc] init];
result = [moc_ executeFetchRequest:fetchRequest error:&error];
//return result;
NSLog(@"fetch request getQuestionsByParent: %u found (sub variables:%@, results:%@)", [result count], dictionary, result);
NSManagedObject *firstManagedObject = [result objectAtIndex:0];