当前位置:  开发笔记 > IOS > 正文

核心数据NSPredicate的关系

如何解决《核心数据NSPredicate的关系》经验,为你挑选了1个好方法。

我的对象图很简单.

我有一个feedentry对象,它存储有关RSS提要的信息和一个名为Tag的关系,该关系链接到"TagValues"对象.关系(to和inverse)都是to-many.即,馈送可以具有多个标签,并且标签可以与多个馈送相关联.

我提到了如何通过关系进行核心数据查询?并创建了一个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; 

-



1> respectTheCo..:

这里的关键是"任何"

苹果的例子:

NSPredicate *predicate = [NSPredicate predicateWithFormat:
    @"ANY employees.firstName like 'Matthew'"];

http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreData/Articles/cdBindings.html

推荐阅读
手机用户2402852307
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有