【发布时间】:2010-10-29 22:02:21
【问题描述】:
我的对象图很简单。
我有一个 feedentry 对象,它存储有关 RSS 提要的信息和一个名为 Tag 的关系,它链接到“TagValues”对象。关系(到和逆)都是对多的。也就是说,一个提要可以有多个标签,一个标签可以关联到多个提要。
我参考了How to do Core Data queries through a relationship? 并创建了一个 NSFetchRequest。但是当获取数据时,我得到一个异常说明,
NSInvalidArgumentException 未实现的谓词 SQL 生成
我该怎么办?我是核心数据的新手 :( 我知道我做错了什么...请帮助...
谢谢
--
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// Edit the entity name as appropriate.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"FeedEntry" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
// Edit the sort key as appropriate.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"authorname" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
NSEntityDescription *tagEntity = [NSEntityDescription entityForName:@"TagValues" inManagedObjectContext:self.managedObjectContext];
NSPredicate *tagPredicate = [NSPredicate predicateWithFormat:@"tagName LIKE[c] 'nyt'"];
NSFetchRequest *tagRequest = [[NSFetchRequest alloc] init];
[tagRequest setEntity:tagEntity];
[tagRequest setPredicate:tagPredicate];
NSError *error = nil;
NSArray* predicates = [self.managedObjectContext executeFetchRequest:tagRequest error:&error];
TagValues *tv = (TagValues*) [predicates objectAtIndex:0];
NSLog(tv.tagName); // it is nyt here...
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"tag IN %@", predicates];
[fetchRequest setPredicate:predicate];
// Edit the section name key path and cache name if appropriate.
// nil for section name key path means "no sections".
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
aFetchedResultsController.delegate = self;
self.fetchedResultsController = aFetchedResultsController;
--
【问题讨论】:
-
贴出你的一些代码,让我们看得更清楚
-
Mungunth,在将谓词重新设置为“标记 IN 谓词”后,您可能忘记设置 fetchRequest 的实体。如果这不是问题,请同时发布对象模型的图片,我可以为您提供更多指导。
-
Mugunth> 您应该添加您的解决方案作为答案并接受它。
-
我通过 devforums.apple.com 得到了答案。在 NDA 到位之前,我不能透露答案...... :(
标签: iphone cocoa cocoa-touch core-data osx-leopard