- 我有一个Item实体和一个Tag实体. - 项目可以有多个标签,标签可以链接到多个项目(多对多关系). - 这种关系是两种方式的"有序关系"(在IOS5中使用有序关系).
我想获取给定项目的所有子标签
我使用以下获取请求:
NSFetchRequest* request = [NSFetchRequest fetchRequestWithEntityName:@"Item"];
// Fetch all items that have a given tag
Tag* myTag = ....;
request.predicate = [NSPredicate predicateWithFormat:@"ANY tag == %@", myTag];
// This is my attempt to get the correct sort ordering (it crashes)
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"tag"
ascending:YES];
request.sortDescriptors = @[sortDescriptor];
Run Code Online (Sandbox Code Playgroud)
上面的排序描述符返回数据(我假设是按某种顺序)但随后崩溃:
[_NSFaultingMutableOrderedSet compare:]: unrecognized selector sent to instance 0x10b058f0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[_NSFaultingMutableOrderedSet compare:]: …Run Code Online (Sandbox Code Playgroud)