numberFormatter long shot question

I know this is a long shot. and I've looked at the docs, and it doesn't seem like its a possibility. But I figured I'd ask here just in case I didn't see something important.


I have recently added NSNumberFormatter to my workflow, and it works great for most things. There's just one instance where it doesn't seem to have capability.


and that's formatting the display of Arrays of numbers.

for instance:

let arr = [0.0, 3.4, 6.6, 9.99, 124.0]

might display as :

0.0 - 124.0


I have a solution, that works great. but it's an either or proposition. I can't use NSNumber formatter AND my solution. I have to choose. and frankly: NSNumberFormatter is very convenient. So... is there a special class of number formatter that Might be able to handle this kind of Number transform to String? or am I right in assuming that no... number formatters aren't intended to work like that?

Replies

So you want to replace the array list with just the range of it ?

I don't think iot exists, but you could sublcass Formatter to do this.


https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/DataFormatting/Articles/CreatingACustomFormatter.html#//apple_ref/doc/uid/20000196


If I had to, I would first filter for minimum and maximum values and then apply the basic formatter to the numbers ; finally add the separation dash.