I question if it's possible (and just how) use a class in Objective-C with something similar to:
That may be very handy for any project I am doing.
I love by doing this of coding contained in Django &lifier SubSonic.
I believe specific for your example this is the same in Cacao:
NSArray *people = /* array of people objects */ NSPredicate *pred = [NSPredicate predicateWithFormat:@"Id = 1 AND Id != 2"]; NSSortDescriptor *byName = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES]; NSArray *descriptors = [NSArray arrayWithObject:[byName autorelease]]; NSArray *matches = [people filteredArrayUsingPredicate:pred]; NSArray *sortedMatches = [matches sortedArrayUsingDescriptors:descriptors]; NSArray *justNames = [sortedMatches valueForKey:@"Name"];
It's a bit more verbose compared to LINQ example plus some of my lines might have been combined but to my attention this really is simpler to parse.
The short response is that there's no equal to Linq for Objective-C however, you can fake it with a mixture of SQLite, NSPredicate and CoreData calls inside a wrapper class formed the way you like. You'd most likely want to consider the core data guide, the predicate guide, and this situation code.
In the above predicate guide:
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:managedObjectContext]; [request setEntity:entity]; // assume salaryLimit defined as an NSNumber variable NSPredicate *predicate = [NSPredicate predicateWithFormat: @"salary > %@", salaryLimit]; [request setPredicate:predicate]; NSError *error = nil; NSArray *array = [managedObjectContext executeFetchRequest:request error:&error];
There's an acticle evaluating the Home windows and Cacao methods for carrying this out. Cacao uses Key Pathways And NSPredicate....
Mmm ok, however how put it on to some Sqlite query and never a completely loaded array?
Browse the following repository: https://github.com/ziminji/objective-c-sql-query-builder
These classes provides some convenience techniques you can use to construct well-created SQL queries rapidly for Sqlite. They're quite easy to use and therefore are relatively easy given that they follow fundamental SQL syntax.