Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从实体具有NSSet的coredata检索数据_Ios_Sqlite_Core Data_Nsset - Fatal编程技术网

Ios 从实体具有NSSet的coredata检索数据

Ios 从实体具有NSSet的coredata检索数据,ios,sqlite,core-data,nsset,Ios,Sqlite,Core Data,Nsset,我试图使用谓词获取我要搜索的数据位于NSSet @property (nonatomic, retain) NSSet *categories; @property (nonatomic, retain) NSString *otherDetails; @property (nonatomic, retain) NSNumber *id; NSSet类别由另一个实体组成,包含: @property (nonatomic, retain) NSString *name; @property (n

我试图使用谓词获取我要搜索的数据位于
NSSet

@property (nonatomic, retain) NSSet *categories;
@property (nonatomic, retain) NSString *otherDetails;
@property (nonatomic, retain) NSNumber *id;
NSSet
类别由另一个实体组成,包含:

@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSNumber *id;
然后尝试通过一个谓词来获取它

NSFetchRequest *fetcher =[NSFetchRequest fetchRequestWithEntityName:@"MyEntity"];
fetcher.predicate = [NSPredicate predicateWithFormat:@categories in  %@", catList];
NSArray *catList = array of Category objects;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY myEntity.categories IN %@", catList];
其中catList是:

NSmutableArray *catList = [[NSMutableArray alloc] init];
并且被数据填充

这给了我以下的错误

'NSInvalidArgumetException', reason: 'unimplemented SQL generation for predicate: (categories IN {"this", "that"});
我尝试将其更改为使用类似这样的
NSSet
字段

fetcher.predicate = [NSPredicate predicateWithFormat:@categories.name in  %@", catList];
但这不起作用

如果我将谓词更改为使用
NSString
,则不会出错,但由于数据不同,因此不会返回结果

fetcher.predicate = [NSPredicate predicateWithFormat:@categories in  %@", catList];
那么,我必须如何使用谓词在
NSSet
上执行查询呢

更新: 我发现这可能会解决张贴的问题,但我把它简化了一点

我实际上拥有的是另一个实体,它有一大堆我正在搜索的细节,然后与我的“MyEntity”实体有多对一的关系

我的心:

@property (nonatomic, retain) NSNumber *searchField1;
@property (nonatomic, retain) NSNumber *searchField2;
@property (nonatomic, retain) MyEntity *myEntity;
@property (nonatomic, retain) NSNumber *id;
像这样的请求

NSFetchRequest *fetcher =[NSFetchRequest fetchRequestWithEntityName:@"MySearchEntity"];
fetcher.predicate = [NSPredicate predicateWithFormat:@"myEntity.otherDetails CONTAINS %@ && searchField1 <= %f && searchField2 >= %f && myEntity.categories.name in  %@", catList];
NSFetchRequest*fetcher=[NSFetchRequest fetchRequestWithEntityName:@“MySearchEntity]”;
fetcher.predicate=[NSPredicate predicateWithFormat:@“myEntity.otherDetails包含%@&&searchField1=%f&&myEntity.categories.name in%@”,catList];

因此,语句的其余部分可以工作,但我仍然无法通过MyEntities与categories的多对多关系对其进行过滤。

要查找相关的MyEntity对象在给定集中至少有一个类别的
MyEntity
对象,可以使用谓词

NSFetchRequest *fetcher =[NSFetchRequest fetchRequestWithEntityName:@"MyEntity"];
fetcher.predicate = [NSPredicate predicateWithFormat:@categories in  %@", catList];
NSArray *catList = array of Category objects;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY myEntity.categories IN %@", catList];
或者,如果类别按名称给出:

NSArray *catList = array of NSString objects;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY myEntity.categories.name IN %@", catList];

谓词的目标是什么?它将类别限制为添加到catList中的选定类别。因为对于每个对象,类别是一组(多个)对象,所以您希望获取什么?类别等于catList或catList子集的所有对象?或者至少有一个catList类别的所有对象?catList是所有可能类别的子集(通过其他地方的用户交互设置)。这并不能回答我的问题。你想拿什么东西?太棒了。“任何”都是我所缺少的,它让世界变得不同。谢谢马丁在这方面的帮助。我已将此标记为答案。