Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/martydill/ios-queryable
ios-queryable is an implementation of IQueryable/IEnumerable for Core Data
https://github.com/martydill/ios-queryable
Last synced: 18 days ago
JSON representation
ios-queryable is an implementation of IQueryable/IEnumerable for Core Data
- Host: GitHub
- URL: https://github.com/martydill/ios-queryable
- Owner: martydill
- License: mit
- Created: 2012-11-11T20:55:42.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2015-09-01T20:42:30.000Z (about 9 years ago)
- Last Synced: 2024-10-19T18:28:23.888Z (25 days ago)
- Language: Objective-C
- Size: 607 KB
- Stars: 227
- Watchers: 15
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - ios-queryable - ios-queryable is an implementation of IQueryable/IEnumerable for Core Data (etc)
- awesome - ios-queryable - ios-queryable is an implementation of IQueryable/IEnumerable for Core Data (etc)
README
#ios-queryable is an Objective-C category that provides IQueryable and IEnumerable-like functionality to Core Data.
Tired of writing boilerplate Core Data code? Can't live without LINQ? ios-queryable is for you!
It supports query composition and deferred execution, and implements a subset of IEnumerable's methods, including where, take, skip, orderBy, first/firstOrDefault, single/singleOrDefault, count, any, and all.
It lets you write code like this:
```objc
NSArray* widgets = [[[[[self.managedObjectContext ofType:@"Widget"]
where:@"Type == 'abc'"]
orderBy:@"createddate"]
take:5]
toArray];
```instead of like this:
```objc
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
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];
```It also supports the NSFastEnumeration protocol, allowing for easy use in foreach loops:
```objc
foreach(Widget* widget in [self.managedObjectContext ofType:@"Widget"])
{
// Do widgety stuff
}
```
#Usage
To use ios-queryable, simply copy NSManagedObjectContext+IQueryable.h and NSManagedObjectContext+IQueryable.m into your project folder. Then, simply include the header file, and start writing your queries!For examples, check out the tests in the tests project.