字符串过滤器的核心数据数组 [英] core data array of string filter

查看:55
本文介绍了字符串过滤器的核心数据数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我有一组数据,每个数据都有一个称为类型的属性。 type是一个字符串值数组,例如:

I have a set of data, each of them has an attribute called "type". "type" is an array of String values, like:

data1 = {"type": ["car", "truck", "plane"]}

在核心数据中,我将类型存储为可变形

in core data, I store "type" as Transformable

需要:

现在,我需要通过检查给定数组中的类型是否包含任何值来过滤这些数据,例如:

Now, I need to filter these data by checking if there "type" contains ANY value in an given array, like:

["pickup", "plane"]

因此,上一节中的data1应该是合格的。

so, data1 in the previous section should be qualified.

问题:

有人可以帮我弄清楚吗?

Could anyone help me to figure out an working NSPredicate to get what I want?

我尝试了 CONTAINS, SUBQUERY,但没有一个起作用。

I tried "CONTAINS", "SUBQUERY", but none of them works.

非常感谢!

推荐答案

没有这样的谓词。您不能将可转换值用作谓词的一部分,除非(可能)正在检查是否相等。也就是说,如果您有一个数组并对其进行了转换,则应该能够过滤出具有该确切值的对象。

There is no such predicate. You cannot use transformable values as part of a predicate, except (probably) if you're checking for equality. That is, if you had an array and transformed it, you should be able to filter for objects with that exact value.

转换后的值是一系列字节,表示为在iOS应用中是由 NSData 的实例完成的。此字节Blob没有设置集成员身份或任何其他更高级别含义的指示。只是一点点而已。即使转换了过滤器数组,也无法保证它会与这些字节的子节匹配。

The transformed value is a series of bytes, represented in iOS apps by an instance of NSData. This byte blob has no indication of set membership, or any other higher level meaning. It's just bits. Even if you transformed your filter array, there's no guarantee that it would match a sub-section of those bytes.

如果您需要进行这种过滤,则需要重新考虑如何保存数据。理想情况下,您将有一个名为 Type 的单独实体,您可以在其中保存类型名称,并从当前实体到有一对多关系类型实体。

If you need to do this kind of filtering, you need to reconsider how you're saving your data. Ideally you'd have a separate entity called Type where you could save the type names, and have a to-many relationship from your current entity to the Type entity.

这篇关于字符串过滤器的核心数据数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆