Created
April 3, 2012 19:15
-
-
Save egold/2294834 to your computer and use it in GitHub Desktop.
Quickie NSArray sorting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSSortDescriptor* sortByDate = [NSSortDescriptor sortDescriptorWithKey:@"createdDate" ascending:NO]; | |
allReminders = [allReminders sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortByDate]]; | |
self.reminders = [NSMutableArray arrayWithArray:allReminders]; |
There are more flexible ways to sort NSArrays using blocks or custom methods, but this covers 90% of cases
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This assumes you're sorting an array of objects that have a "createdDate" field.
Any object that conforms to Key Value Coding (KVC) such as NSManagedObjects or NSDictionaries will work with this.
So, you could use it to sort Core Data objects or JSON parsed into dictionaries for instance.