Skip to content

Instantly share code, notes, and snippets.

@erickva
Created June 28, 2016 23:20
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 erickva/11557eb8ff315c32256142c637bc0c9f to your computer and use it in GitHub Desktop.
Save erickva/11557eb8ff315c32256142c637bc0c9f to your computer and use it in GitHub Desktop.
Delete Duplicates and Sort Array of Objects in Objective-C
NSOrderedSet *orderedSet = [NSOrderedSet orderedSetWithArray:_lastMessages];
NSArray *arrayWithoutDuplicates = [orderedSet array];
NSSortDescriptor *dateDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"date_" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
NSArray *sortedEventArray = [arrayWithoutDuplicates sortedArrayUsingDescriptors:sortDescriptors];
_lastMessages = [sortedEventArray mutableCopy];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment