Objective c 使用NSPredicate搜索核心数据实体的NSArray属性

Objective c 使用NSPredicate搜索核心数据实体的NSArray属性,objective-c,core-data,nspredicate,Objective C,Core Data,Nspredicate,为了找到解决这个问题的办法,我到处寻找。我所有的尝试都会导致0个结果。以下是一般数据结构: Core Data Entity A { stringAttribute string .... transformableAttribute(NSArray of NSString objects) keywords } 其中关键字=[NSArray arrayWithObjects:@“字符串1”,“字符串2”,“字符串3”,nil] 我试图运行一个谓词来搜索NSArray transf

为了找到解决这个问题的办法,我到处寻找。我所有的尝试都会导致0个结果。以下是一般数据结构:

Core Data Entity A {
  stringAttribute string
  ....
  transformableAttribute(NSArray of NSString objects) keywords
}
其中关键字=[NSArray arrayWithObjects:@“字符串1”,“字符串2”,“字符串3”,nil]

我试图运行一个谓词来搜索NSArray transformable属性

我对实体A尝试了以下方法。核心数据存储是sqlite存储

NSString *term = @"string 1";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY keywords like[cd] %@", term];
---->结果为0个匹配项

NSArray *termArray = [NSArray arrayWithObject:@"string 1"];
NSPredicate *predicate = [NSPredicate predicateWithFormat@"ANY keywords in %@", termArray];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(keywords, $x, $x like %@).@count > 0", term]
---->结果为0个匹配项

NSArray *termArray = [NSArray arrayWithObject:@"string 1"];
NSPredicate *predicate = [NSPredicate predicateWithFormat@"ANY keywords in %@", termArray];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(keywords, $x, $x like %@).@count > 0", term]
---->导致非关系不能作为子查询集合的错误

我尝试了上面的一些排列,但仍然没有结果。有什么建议吗?对于核心数据,这可能吗


谢谢

我不使用
transformableAttribute
这是一个核心数据元素,但如果我记得的话,你不能对它们进行断言。(因此,如果我错了,请有人就此给我打电话)

但是当我看到你的
transformableAttribute
是一个
字符串数组
时,我只想说
为什么你想要数据库中的数组?

为什么不谈恋爱呢?如果数组可以有不同数量的字符串,则为一对多关系


核心数据是数据库的抽象,在数据库中,您不使用数组,而是使用表。这可能会简化您的生活并使抓取成为可能。

我认为,如果您将字符串数组作为一个单独的实体,并使用关系来连接它们,生活会更轻松。如果这样实现的话,你想做的很容易。是的,我认为一个单独的实体是最好的,就像在SQL中一样。我希望避免迁移,但我找不到更好的方法。我使用的是FetchedResutlsController,它需要通过谓词进行抓取,我无法手动筛选。这似乎是真的。当我使用transformableAttribute在NSPredicate上直接搜索时,许多人发现您不能这样做。可转换属性作为二进制数据存储在数据库中,因此对其执行SQL查询将不起作用。