Saturday, 17 August 2013

NSPredicate won't work?

NSPredicate won't work?

I have a to-many relationship between 2 entities.
Athlete(evals)<-->>Eval(whosEval). I am trying to display only the evals
of the athlete who was selected. However, when I try to access the
relationship through eval.whosEval, I get an undefined error. When I run
the app, the table is empty, whereas if I comment out the predicate, it
displays ALL Evals for ALL the Athletes. Am I missing something? Thank
you.
allEvals.m
-(void)viewWillAppear:(BOOL)animated{
self.title = [NSString stringWithFormat:@"%@ %@'s
Evaluations",_athletesFirstName, _athletesLastName];
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
_managedObjectContext = [appDelegate managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"whosEval ==
%@", _athletesFullName];
[request setPredicate:predicate];
NSEntityDescription *eval = [NSEntityDescription entityForName:@"Eval"
inManagedObjectContext:_managedObjectContext];
[request setEntity:eval];
NSSortDescriptor *sortDescriptor =
[[NSSortDescriptor alloc] initWithKey:@"date_recorded"
ascending:NO
selector:@selector(localizedCaseInsensitiveCompare:)];
NSArray *sortDescriptors = [[NSArray
alloc]initWithObjects:sortDescriptor, nil];
[request setSortDescriptors:sortDescriptors];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[_managedObjectContext
executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil){
//handle error
}
[self setEvalArray:mutableFetchResults];
[self.tableView reloadData];
NSLog(@"Athlete's Full Name is: %@",_athletesFullName);
NSLog(@"This eval is for: %@", eval.whosEval);
//the line above gets an error saying eval.whosEval isnt found on
NSEntityDescription
//How do I access the value of whosEval?
}

No comments:

Post a Comment