问题描述:

I have core data with Entity @"Collection" with attributes payment, date etc and i stored "date"

with respect to date,month,year like "dd-MM-yyyy" but i want to fetch data with respect to only Month and Year so for this purpose what NSPredicate i use. If any one known this then kinldy guide me.

网友答案:

As Droppy commented use NSDate as the field type.

If that is not possible you can fetch the rows you are interested in by using a NSPredicate:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K LIKE[cd] %@", kDateFieldKey, [NSString stringWithFormat:@"*-%02d-%d", month, year]];
fetchRequest.predicate = predicate;

where kDateFieldKey is the key for your date field ("date"), month is an integer representing the month and year is an integer representing the year.

相关阅读:
Top