I\'ve found the following code at http://snipplr.com/view/2771
Which is pretty good, almost exactly what I was looking for, but if I use the values @\"1.4.5\", @
I'm not 100% sure what you're asking, but if you're looking to sort numbers regardless of how many periods "." are in the number you can use an NSSortDescriptor
on a dictionary of OS versions:
NSArray *originalArray = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObject:@"10.4.5" forKey:@"version"],
[NSDictionary dictionaryWithObject:@"10.5.6" forKey:@"version"],
[NSDictionary dictionaryWithObject:@"10.6.8" forKey:@"version"],
[NSDictionary dictionaryWithObject:@"10.8" forKey:@"version"],
[NSDictionary dictionaryWithObject:@"10.7.1" forKey:@"version"],
[NSDictionary dictionaryWithObject:@"10.8.2" forKey:@"version"],
nil];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"version" ascending:true];
NSArray *sortedArray = [originalArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
NSLog(@"Lowest to highest: %@", sortedArray);
NSLog(@"Highest OS version: %@",[[sortedArray objectAtIndex:[sortedArray indexOfObject:[sortedArray lastObject]]] objectForKey:@"version"]);