If the strings are well-formed, with leading zeros, form an NSArray
and then invoke sortedArrayUsingComparator:
. But if you have values like 12:34.567 and 2:34.567, this approach won't work. You'll have to convert, either to double
or NSNumber
, storing seconds (that is, 2:34.567 converts to 154.567).
Note that these are not NSDate objects. An NSDate marks a particular instant in time, and these appear to be simply durations.
If you use NSNumber
, you can still use sortedArrayUsingComparator:
. You'll have to write a subclass of NSFormatter, to convert between mm:ss.SSS and NSNumber and back again.
See the documentation for NSComparator for a blocks-based example. You'll also need the Class Reference for NSFormatter. The FormatterKit project on GitHub has some nice NSFormatter sample code.