RSS

Sort mutable array containing dictionary

16 Dec

NSComparator compareDistances = ^(id string1, id string2)
{
NSNumber *number1 = [NSNumber numberWithFloat:[string1 floatValue]];
NSNumber *number2 = [NSNumber numberWithFloat:[string2 floatValue]];

return [number1 compare:number2];
};

// sort list and create nearest list
NSSortDescriptor *sortDescriptorNearest = [NSSortDescriptor sortDescriptorWithKey:@”petrolStation.pointCoordinates.distance” ascending:YES comparator:compareDistances];
_nearestList = (NSMutableArray *)[_gasStations sortedArrayUsingDescriptors:@[sortDescriptorNearest]];

Advertisements
 
Leave a comment

Posted by on December 16, 2014 in Uncategorized

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: