Sort an NSObject array based on a single value based on a single value inside a single object

I created an object, it looks something like this.

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

This is then added to the mutable array (nearbranch). later I determine the distance of each object to the current gps position and add it to the object and return it back to the array. (aOffice.distance)

Now I need to sort this array based on the value of aOffice.distance, but I don’t know how to do it

can someone help me please

thanks

+6
source share
1 answer
 NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:NO]]; NSArray *sortedArray = [yourArray sortedArrayUsingDescriptors:sortDescriptors]; 
+18
source

Source: https://habr.com/ru/post/958458/


All Articles