Possible Duplicate:
Comparing version numbers
How to use compare on a version number where theres less parts in one number in Objective-C?
I am attempting to sort an NSMutableArray
of custom objects based on a property called referenceID
which essentially resembles a version number.
It seems that treating referenceID
as an NSNumber
and sorting it using compareTo:
almost gets it right, but where it breaks is cases such as:
Result: Should Be:
1.1.1 1.1.1
1.1.10 1.1.2
1.1.2 ...
... 1.1.9
1.1.9 1.1.10
(Where ... is 1.1.2 through 1.1.9)
Are there any built in functions that will sort this properly? Or should I get started writing the sorting algorithm?