Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data NSPredicate for date

In my model I have date attribute and I set it [NSDate date], but getting with predicate like

 NSPredicate *predicate = [NSPredicate predicateWithFormat:
                              @"date==%@ ,date]; 

returns notting. I know the problem is when I set [NSDate date] it stores also time and NSPredicate always return empty data. Is there any way to convert "date==%@" part to only look for date?

like image 740
Ercan Avatar asked Sep 19 '12 17:09

Ercan


People also ask

How is date stored in Core Data?

In a Core Data store, a Date attribute is a double value that represents a number of seconds since 1970. Using a variety of calendars, time zones, and locales, an app can convert a Date value to different date strings, or convert a date string to different Date values.

What is NSPredicate format in Swift?

NSPredicate is a Foundation class that specifies how data should be fetched or filtered. Its query language, which is like a cross between a SQL WHERE clause and a regular expression, provides an expressive, natural language interface to define logical conditions on which a collection is searched.

What is predicate in core Swift?

For example, if you already completed project 33 you'll have seen how predicates let us find iCloud objects by reference. Put simply, a predicate is a filter: you specify the criteria you want to match, and Core Data will ensure that only matching objects get returned.


1 Answers

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(date >= %@) AND (date <= %@)", startDate, endDate];
like image 85
cancerian Avatar answered Nov 20 '22 09:11

cancerian