Pick closest NSNumber from array
I have an array with a bunch of NSNumber s. From an UISlider I get a certain value when the user stops dragging it. I would like to get the closes number from the array. So for instance, if the user drags the UISlider to 13 , and the NSArray contains the NSNumbers with 10 and 15 ; I want to get 15 from the array. Example of array: NSArray *values = [NSArray arrayWithObjects:[NSNumber numberWithInt:15], [NSNumber numberWithInt:20], [NSNumber numberWithInt:30], [NSNumber numberWithInt:45], [NSNumber numberWithInt:60], [NSNumber numberWithInt:90], [NSNumber numberWithInt:110], nil]; How do I get