如何对 fetchRequest 上的第一次出现进行谓词
我正在尝试找到一种方法来预测某一天事件的第一次发生。假设一个事件在一天中发生多次(范围 1-16),我只希望它返回第一次出现的事件,然后在第二天查找下一个第一次出现的事件。
I'm trying to find a way of predicating for the first occurrence of an event on a given day. So say an event occurs multiple times during the day (range 1-16), I only want it to return the first occurrence and then look for the next first occurrence on the following day.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法通过一个 fetchRequest 来完成此操作;你需要做两个。
对于每一天,只需使用谓词来限制当天开始后的出现次数,按日期升序排序,然后仅获取一项:
当然,您需要检查获取的项以确保它仍然存在同一天。然后,第二天重复。
You won't be able to do this with one fetchRequest; you'll need to do two.
For each day, just use a predicate to limit to occurrences after the beginning of that day, sort in ascending order of date, and fetch only one item:
Of course, you'll want to check the item you get to make sure it's still on the same day. Then, repeat for the next day.