Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sorting an array of NSObject based on one value based on one value within one object

i have created an object, it looks something like this

aOffice.branchname 
aOffice.lat
aOffice.lng
aOffice.distance

this is then added to an mutable array (nearbranch). later on i work out the distance of each object to the current gps position and add that into the object and put it back into the array. (aOffice.distance)

i now need to sort that array based on the value of aOffice.distance but have no idea how to do it

could someone help me out please

Thanks

like image 573
richard Stephenson Avatar asked Nov 20 '13 09:11

richard Stephenson


1 Answers

NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:NO]];
NSArray *sortedArray = [yourArray sortedArrayUsingDescriptors:sortDescriptors];
like image 166
Akki Avatar answered Oct 31 '22 18:10

Akki