NSPredicate仅在“年”上过滤。日期字段的一部分

编程入门 行业动态 更新时间:2024-10-24 12:27:50
本文介绍了NSPredicate仅在“年”上过滤。日期字段的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个具有日期字段的实体,我想选择给定年份的记录。如何构建一个NSPredicate的工作?在Core Data中找不到任何关于日期函数(如果有的话)

I have an entity with a date field and I would like to select the records for a given year. How to build a NSPredicate for the job? Didn't find anything about date functions (if any) in Core Data

感谢

推荐答案

一种可能的方法:

步骤1)请参阅Apple的日期和时间编程指南中的从组件创建日期。创建一个表示年初的NSDate,以及表示年底的NSDate。

Step 1) See "Creating a Date from Components" from Apple's "Date and Time Programming Guide." Make an NSDate representing the beginning of the year, and an NSDate representing the end of the year.

步骤2)然后,您可以构建一个谓词,

Step 2) Then you could build a predicate that searches for objects with date attrs that are greater than the first date and less than the last date.

谓词看起来像这样:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(inceptionDate > %@) AND (inceptionDate < %@)", dateBeginYear, dateEndYear];

更多推荐

NSPredicate仅在“年”上过滤。日期字段的一部分

本文发布于:2023-11-22 20:09:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618836.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   日期   NSPredicate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!