有点复杂 NSPredicate (IOS)ha

发布于 2025-01-02 09:12:01 字数 605 浏览 0 评论 0原文

现在,我需要对 NSFetchRequest 使用谓词。

但这里的情况有点不同,因为谓词要经历两个嵌套对多关系。

例如,我的实体是这样的:

在此处输入图像描述

现在我需要获取一些月和周 ManagedObjects,但是要求是所需周或月中一天的事件数量多于一个。

换句话说,对于给定的周或月,如果其“天”关系的目的地上的任何一天至少有一个事件,则接受它。

所以这是一个嵌套的多对多关系,我不知道如何设置谓词字符串。

有两个麻烦:

  1. 我知道 ALL 和 ANY 关键字。但是@“ANY days.ANY events”可以是关键路径吗?或者应该如何?

  2. 如何判断事件关系至少指向一个Event对象。

[@"%K != nil",theCorrectKeypath] 有效吗?我担心“!= nil”不等于至少一个目标对象?

等待有人来帮助我。

非常感谢!

Now, I need to use a predicate for a NSFetchRequest.

But things here are a little different, since there are two nested to-many relationships for the predicate to go through.

For instance, my entities are like this:

enter image description here

Now I need to fetch some Month and Week ManagedObjects, but the requirement is that the amount of Events of a Day of the needed Weeks or Months is more than one.

In another word, with reference to a given Week or Month, if any Day on the destination of its "days" relationship has at least one Event, then take it.

So that is a nested to-many relationship, and I don't know how to set the predicate string.

There are two troubles:

  1. I know ALL and ANY keyword. But could @"ANY days.ANY events" be the keypath? Or how is it supposed to be?

  2. How to judge that the events relationship points to at least one Event object.

Would [@"%K != nil",theCorrectKeypath] work? I'm afraid of that "!= nil" does not equal to at least one destination object?

Waiting for someone to help me out.

Terribly thanks!

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

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

发布评论

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

评论(1

彡翼 2025-01-09 09:12:01

我自己找到了答案。

还有另一种方法可以得到这个,因为我的条件,我可以只谓词合适的Events对象,并且从Events到Week或Month都是一对一的关系,

所以一旦我得到了符合条件的Events,

我就可以得到相应的 划分的周和月

按Event.date.thisWeek 或theEvent.date.thisMonth

。谢谢你们,

I found the answer my self.

There's another way to get this, because of my condition, I can just predicate the suitable Events objects, and all the way from Events to Week or Month are to-one relationship,

so once I got the eligible Events,

I can just get corresponding Weeks and Months by

theEvent.date.thisWeek or theEvent.date.thisMonth.

Thanks for your guys,

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