Skip to content

Instantly share code, notes, and snippets.

@ashtom
Created March 16, 2012 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashtom/2049389 to your computer and use it in GitHub Desktop.
Save ashtom/2049389 to your computer and use it in GitHub Desktop.
Sort by pubDate
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDictionary *one = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:1], @"pubDate", nil];
NSDictionary *two = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:2], @"pubDate", nil];
NSDictionary *three = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:3], @"pubDate", nil];
NSArray *array = [NSArray arrayWithObjects:three, one, two, nil];
NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"pubDate" ascending:YES] autorelease];
NSLog(@"%@", [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]);
[pool drain];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment