Created
February 16, 2016 05:36
-
-
Save irshadpc/9fd7ea67a0a0de8bbb13 to your computer and use it in GitHub Desktop.
Coredata data fetch between two dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| + (NSArray*)allEntriesInContext:(NSManagedObjectContext*)context fromDate:(NSDate*)fromDate toDate:(NSDate*)toDate{ | |
| // Create the request | |
| NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Entry"]; | |
| // Build the predicate | |
| NSPredicate *predicate = [NSPredicate predicateWithFormat: @"date >= %@ && date <= %@ ", fromDate, toDate]; | |
| request.predicate = predicate; | |
| // Define sorting | |
| NSSortDescriptor *sortDesc = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:YES]; | |
| request.sortDescriptors = @[sortDesc]; | |
| // Execute the request | |
| NSError *error; | |
| NSArray *entries = [context executeFetchRequest:request error:&error]; | |
| if(error){ | |
| //!!!b Error management | |
| } | |
| return entries; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment