我正在制作一个应用程序,里面有一个问卷,我使用Core data来保存它的所有数据。
有三个实体: Person (接受问卷调查的人),There (问题),QuestionResult (问题的结果)
Person链接到链接到问题的QuestionResult,所有这些都通过关系实现。
给定一个Person和there实体,我希望能够找到两者之间是否有关联的QuestionResult对象。使用NSPredicate可以做到这一点吗?
发布于 2013-01-23 22:55:20
设置:
Person <<------->> Question
Person <-------->> Answer
Question <------>> Answer解决方案:
NSSet *filtered = [person.answers filteredSetUsingPredicate:
[NSPredicate predicateWithFormat:@"question == %@", questionObject]];
BOOL thereIsAnAnswer = filtered.count != 0;或者,如果您不需要将问题分配给某个人,除非有答案,您可以简化模型:
Person <---------->> Answer <<----------> Question;谓词应该是完全相同的。
https://stackoverflow.com/questions/14481665
复制相似问题