小编Ash*_*Ash的帖子

核心数据:在多对多关系中,我应该使用什么作为具有有序集(ios5)的排序描述符

在此输入图像描述- 我有一个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)

core-data nspredicate ios

10
推荐指数
1
解决办法
3716
查看次数

标签 统计

core-data ×1

ios ×1

nspredicate ×1