Skip to content

Instantly share code, notes, and snippets.

@lukestringer90
Created October 4, 2012 13:41
Show Gist options
  • Save lukestringer90/3833592 to your computer and use it in GitHub Desktop.
Save lukestringer90/3833592 to your computer and use it in GitHub Desktop.
Macros for NSPredicate and NSSortDescriptor
#define pred(format) [NSPredicate predicateWithFormat:format]
#define sort(key, asc) [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:key ascending:asc]]
//array of core data entities (giggle!)
NSArray *entities = (.)(.)
//filter array
NSArray *filtered = [entities filteredArrayUsingPredicate:pred(@"timestamp != nil")];
//sort array
NSArray *sorted = [entities sortedArrayUsingDescriptors:sort(@"timestamp", YES)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment