iPhone-核心数据在获取的NSSet属性中检查

iPhone-核心数据在获取的NSSet属性中检查,iphone,core-data,Iphone,Core Data,我有一个由书籍和捆绑包组成的核心数据结构。一本书可以属于一个或多个包,因此,我在这两个包之间有一个多对多属性。在书本上,此属性称为fromBundle 我对每个实体都有自己的类。这门课是在我有一对多关系的时候写的。。。所以,在那个时候,fromBundle不是NSSet。我的问题是,我必须构建一个谓词,该谓词可以查看fromBundle NSSet内部,并查看该集合是否包含我要查找的bundle 这是我在更改之前的代码 Bundle *aBundle = [Bundle bundleComNum

我有一个由书籍和捆绑包组成的核心数据结构。一本书可以属于一个或多个包,因此,我在这两个包之间有一个多对多属性。在书本上,此属性称为fromBundle

我对每个实体都有自己的类。这门课是在我有一对多关系的时候写的。。。所以,在那个时候,fromBundle不是NSSet。我的问题是,我必须构建一个谓词,该谓词可以查看fromBundle NSSet内部,并查看该集合是否包含我要查找的bundle

这是我在更改之前的代码

Bundle *aBundle = [Bundle bundleComNumber:aNumber  inManagedObjectContext:context];


NSArray *all = nil;

NSFetchRequest *request = [[NSFetchRequest alloc] init];

request.entity = [NSEntityDescription entityForName:@"Book" inManagedObjectContext:context];

// the problem is on the next line... as I see, the line is not looking inside the NSSet
// I may be wrong, but when I run this, it crashes and stops on the executeFetchRequest line
// saying **to-many key not allowed here**

request.predicate = [NSPredicate predicateWithFormat:
                     @"(fromBundle == %@)", aBundle];


[request setResultType:NSDictionaryResultType];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:[NSArray arrayWithObjects: @"Name", @"Number", nil]];


NSSortDescriptor *sortByItem =  [NSSortDescriptor sortDescriptorWithKey:ordem ascending:YES selector:@selector(compare:)];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortByItem];
[request setSortDescriptors:sortDescriptors];



NSError *error = nil;
all = [context executeFetchRequest:request error:&error];  // it is crashing here saying **to-many key not allowed here**
[request release];

return all;
我错过了什么?
谢谢

你试过在fromBundle中使用类似于
@“%@的谓词吗?

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!谢谢我爱这个社区!!!!