code_junkie

Is there something similar to LINQ in Objective-C?

Nov 13th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Person.Select(@"Name").OrderAsc(@"Name").Where(@"Id").EqualTo(1).And(@"Id").NotEqualTo(2).Load<Array>
  2.  
  3. NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
  4. NSEntityDescription *entity = [NSEntityDescription entityForName:@"Employee"
  5. inManagedObjectContext:managedObjectContext];
  6. [request setEntity:entity];
  7. // assume salaryLimit defined as an NSNumber variable
  8. NSPredicate *predicate = [NSPredicate predicateWithFormat:
  9. @"salary > %@", salaryLimit];
  10. [request setPredicate:predicate];
  11. NSError *error = nil;
  12. NSArray *array = [managedObjectContext executeFetchRequest:request error:&error];
  13.  
  14. NSArray *people = /* array of people objects */
  15.  
  16. NSPredicate *pred = [NSPredicate predicateWithFormat:@"Id = 1 AND Id != 2"];
  17. NSSortDescriptor *byName = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES];
  18. NSArray *descriptors = [NSArray arrayWithObject:[byName autorelease]];
  19.  
  20. NSArray *matches = [people filteredArrayUsingPredicate:pred];
  21. NSArray *sortedMatches = [matches sortedArrayUsingDescriptors:descriptors];
  22.  
  23. NSArray *justNames = [sortedMatches valueForKey:@"Name"];
Add Comment
Please, Sign In to add comment