1

如果我使用的数据模型定义了'教师'和'学生'。 '老师'和'学生'是一对多的。使用CoreData和NSFetchedResultsController的一些问题

如:

student.whoTeach = teacher 

我想用NSPredicate获得“学生”的NSFetchedResultsController,这些学生都是一样的老师,然后我会告诉他们UITableView

但我不知道如何得到'同一位老师'。


NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Student"]; 

request.predicate = [NSPredicate predicateWithFormat:]; // This I don't know how to code! 

_fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:request 
managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil]; 

+0

request.predicate = [NSPredicate predicateWithFormat:@“whoTeach ==%@”,self.teacher]; // 这是正确的 ? – Jellyfish 2014-11-03 02:59:00

回答

0

是的,这是正确的jellysfinsh

你可以使用上面的语法使用此语法

request.predicate获得相关的老师对学生的信息, = [NSPredicate predicateWithFormat:@“whoTeach ==%@”,self.teacher];

相关问题