0

I have an array containing all string values. Contents of the array are order_id, waypoint_x, waypoint_y. How do I sort it based on order_id and have the results like 1, 2, 3, 4.... (i.e. as if the field was an integer type and string)

When I use the waypoints as the array is at the moment the results come out 1, 10, 11, 12...

Regards, Stephen

Stephen
  • 4,715
  • 8
  • 53
  • 78

1 Answers1

2

If you check the documentation of NSArray, you'll see there are different methods for sorting the array: sortedArrayUsingFunction, sortedArrayUsingSelector, sortedArrayUsingComparator, etc.

There's a nice example of how to use sortedArrayUsingFunction to sort with integer values in the answer to this question: Sorting an array of doubles or CLLocationDistance values on the iPhone

Community
  • 1
  • 1
Meta-Knight
  • 17,626
  • 1
  • 48
  • 58