I’ve mentioned a number of excellent tools and libraries for working with Core Data, most recently the excellent PonyDebugger editor.
Here’s a new library from Marty Dill called iOS-Queryable that aims to simplify the creation of complex Core Data queries.
The library allows you to eliminate most of the boiler plate code when created complex core data queries by bringing a subset of methods from the IQueryable and IEnumerable libraries from Microsoft.NET LINQ framework.
This is best shown with an example and the example given on the readme is that with this library you can write code like this:
where:@"Type == ‘abc’"]
orderBy:@"createddate"]
take:5]
toArray];
Instead of:
NSEntityDescription* entity = [NSEntityDescription
entityForName:@"Widget" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate* predicate = [NSPredicate predicateWithFormat: @"type == ‘abc’"];
[fetchRequest setPredicate:predicate];
NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:@"createddate" ascending:YES];
NSArray* sortDescriptors = [[NSArray alloc] initWithObjects: sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[fetchRequest setFetchLimit:5];
NSError* error;
NSArray* widgets = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
You can find iOS-Queryable on Github here.
There’s much more to the library than what’s been shown here, and you’ll definitely want to check it out if you find yourself writing some complex core data queries.
Original article: iOS Library For Simplifying Complex Core Data Queries Inspired By Microsoft .NET’s LINQ
©2012 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.





