所以我迷失在这一个。我试图使用谓词获取父对象的子对象。如果我取出谓词行,它将返回所有特定帖子。所以我很确定这是谓词的问题。任何帮助将不胜感激!以下是我的设置。
AccountTimeLine - > SpecificPosts(一对多)
核心数据模型:
获取结果控制器:
- (void)specificPostFetch
{
DataAccessLayer *delegate = [[DataAccessLayer alloc]init];
self.managedObjectContext = delegate.managedObjectContext;
NSString *entityName = @"SpecificPosts";
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"createdDateSort" ascending:YES]];
request.predicate = [NSPredicate predicateWithFormat:@"accountTimeLine = %@", self.accountTimeLineObject];
[request setFetchBatchSize:20];
self.specificPostFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
self.specificPostFetchedResultsController.delegate = self;
[self.specificPostFetchedResultsController performFetch:nil];
}
打印出用于在谓词
中进行比较的accountTimeLineObjectpo self.accountTimeLineObject
<AccountTimeLine: 0x7c087b70> (entity: AccountTimeLine; id: 0x7c086590 <x-coredata://353F201D-E739-4DD0-BEBF-DAD6101CFE51/AccountTimeLine/p72> ; data: {
accountType = 0;
nextPageUrl = 515986477864337411;
sort = 0;
specificPosts = "<relationship fault: 0x7c634590 'specificPosts'>";
userAccountId = 582;
})
答案 0 :(得分:0)
尝试将==放在谓词中,而不是单个=:
request.predicate = [NSPredicate predicateWithFormat:@"accountTimeLine == %@", self.accountTimeLineObject];