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
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A possible method:
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.
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.
The predicate would look something like this: