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?
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.
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.
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.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(date >= %@) AND (date <= %@)", startDate, endDate];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With