如何从核心数据中检索上个月的条目

发布于 2024-12-29 12:18:42 字数 45 浏览 2 评论 0原文

我如何要求核心数据获取最近输入的 30 个元素,或者今天一个月内输入的元素?

how do I ask core data to fetch me the last 30 elements entered or alternatively the elements entered within a month of today?

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

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

发布评论

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

评论(1

眼趣 2025-01-05 12:18:42

要获取一定数量的记录,请结合使用 [fetchRequest setFetchLimit:30] 等限定条件以及所需的 NSPredicate 实例。

要检索某个时间范围内的元素,您需要首先计算所需时间段的开始和结束 NSDate 实例,然后对谓词实例进行编码,如下所示:

NSPredicate *predicate = [NSPredicate predicateWithFormat:
            @"(date >= %@) AND (date <= %@)", startDate, endDate];

请参阅 这个这个

To fetch a certain number of records, use qualification like [fetchRequest setFetchLimit:30] in combination with NSPredicate instance you desired.

To retrieve elements within a range of time, you need first calculate the beginning and the end NSDate instances of the period you want, then code your predicate instance like:

NSPredicate *predicate = [NSPredicate predicateWithFormat:
            @"(date >= %@) AND (date <= %@)", startDate, endDate];

See this and this.

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