子集的 NSPredicate 查询和“足够接近”子集

发布于 2024-12-05 00:23:24 字数 723 浏览 3 评论 0原文

一般来说,对 NSPredicates 和核心数据有点陌生,因此尝试掌握我的头脑需要执行以下操作:

我有两个具有多对多关系的实体:

MyContainerEntity code> 包含与 MyObjectEntity 的多对多关系。

假设 MyObjectEntity 的列表为: A、B、C、D、E、F

并且 MyContainerEntity 的组成为:

Container1 - A, B, C
Container2 - B, C, D
Container3 - A, B, D
Container4 - A, D, F

也就是说,Container1 包含与 的关系MyObjectEntity A、B 和 C 等等。

我想进行一个查询,在其中发送 MyObjectEntity 列表,并返回作为该列表子集的所有 MyContainerEntity 对象。

例如:

(A,B,D,F) 将返回 Container3 和 Container4。

然后,后续操作将得到一些“接近”的结果,并带有一些错误值。假设只有 1 个物体丢失。例如:

(A, B) 将返回 Container1 和 Container3

任何帮助将不胜感激。

Bit new to NSPredicates and Core Data in general, so trying to grasp my head around need to do the following:

I have two Entities that have a Many-to-many relationship:

MyContainerEntity contains a many to many relationship with MyObjectEntity.

Say the list of MyObjectEntity is: A, B, C, D, E, F

And MyContainerEntity is made up of:

Container1 - A, B, C
Container2 - B, C, D
Container3 - A, B, D
Container4 - A, D, F

That is, Container1 contains a relationship with MyObjectEntity A, B and C and so on.

I would like to make a query where I send in a list of MyObjectEntity and all MyContainerEntity objects that are a subset of that list are returned.

For example:

(A,B,D,F) would return Container3, and Container4.

Then the follow up would be getting something that is "close" with some error value. Say only 1 object missing. For example:

(A, B) would return Container1 and Container3

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

口干舌燥 2024-12-12 00:23:24

为了解决问题的第一部分,您是否尝试定义一个谓词,例如:

ALL objects IN $OBJECTS_PARAM

其中 OBJECTS_PARAM 值将是一个数组或通过“predicateWithSubstitutionVariables”参数传递给评估的集合?

对于后续问题,我不确定是否可以直接在谓词中进行。看起来在代码中手动实现这样的查询可能比依赖 NSPredicate 更好。

To get the first part of your problem, have you tried defining a predicate such as:

ALL objects IN $OBJECTS_PARAM

where OBJECTS_PARAM value would be an array or set that you pass into to the evaluation via a "predicateWithSubstitutionVariables" argument?

For the follow up question, I'm not sure if it is possible directly in a predicate. It seems like it might be better to implement such a query manually in code rather than relying on an NSPredicate to do that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文