Search code examples
cocoafoundationnsnumberformatter

Correct Usage of NumberFormatter textAttributesFor Variables?


The Foundation class, NumberFormatter, has a collection of instance variables under the category:

Configuring the Display of Numeric Values

that are all very similar:

var textAttributesForNegativeValues: [String : Any]?
var textAttributesForPositiveValues: [String : Any]?
//...

From what I can tell, these are rarely used, and as such, I haven't been able to find a single example of how to use them, and the Apple API is mute on the issue.

So, does anyone know how to properly use these variables / why they would be used in the first place?


Solution

  • Unfortunately Apple's docs are not the best organised these days, and often useful links seem to have gone AWOL - as here. Read the section on custom formats in the number section of Apple's Data Formatting Guide, and follow the references in it, and you should find the answers you seek.

    HTH