Skip to content

Instantly share code, notes, and snippets.

@nderkach
Last active October 16, 2015 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nderkach/89da0f8beecdef55b302 to your computer and use it in GitHub Desktop.
Save nderkach/89da0f8beecdef55b302 to your computer and use it in GitHub Desktop.
Parse with NSSortDescriptor example
NSSortDescriptor *commonLikesDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"fblikes" ascending:YES comparator:^NSComparisonResult(NSArray* obj1, NSArray* obj2) {
NSMutableSet *intersection1 = [NSMutableSet setWithArray:user[@"fblikes"]];
[intersection1 intersectSet:[NSSet setWithArray:obj1]];
NSMutableSet *intersection2 = [NSMutableSet setWithArray:user[@"fblikes"]];
[intersection2 intersectSet:[NSSet setWithArray:obj2]];
return [@([intersection1 count]) compare:@([intersection2 count])];
}];
__block PFGeoPoint *currentLocation = [PFUser currentUser][@"location"];
NSSortDescriptor *distanceDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"location" ascending:YES comparator:^NSComparisonResult(PFGeoPoint* obj1, PFGeoPoint* obj2) {
return [@([currentLocation distanceInMilesTo:obj1]) compare:@([currentLocation distanceInMilesTo:obj2])];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment