6

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

  • http://stackoverflow.com/questions/6256046/how-to-sort-nsarray-of-objects-based-on-one-attribute use this link – Sport Nov 20 '13 at 09:09

1 Answers1

18
NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:NO]];
NSArray *sortedArray = [yourArray sortedArrayUsingDescriptors:sortDescriptors];
Akki
  • 1,487
  • 14
  • 25