Conversation
Thanks, allow me a couple of days to look into the PR before merging. |
No problem, take your time. |
There are a couple of things you need to review:
|
What do you think about adding the formatter to NSNumber?
My first implementation allowed different formatting but then I noticed that there are a lot of possible configurations (grouping, separator, style, currency, ... ) so I considered easier and more reusable allowing editing the formatter and invoke format. Maybe another possible solution is to add an NSNumberFormatter as a parameter of format |
I didn't think this trough, there isn't a safe way to add this extension without losing the advantages you get by having a shared instance. Exposing the formatter or mutating it in any way (by passing any parameter to the I'm sorry but, unless you have a way to solve these problems, I can't merge this PR. |
I think that a shared instance is necessary. If you use the same format in the entire project you can access to the formatter once (e.g. in the AppDelegate) set the behavior an then invoke format() easily. Otherwise if you have different formats it's necessary to set the behavior every time, but this operation is better than alloc a new formatter and this problem remains with or without this PR. if you don't agree it's not necessary to merge this PR, I will create my own project. |
The point is that every time you alter the shared formatter you need to synchronize the operation across the threads using the instance. As I wrote before, can't merge this (the way it is), sorry. |
Ok! Thanks anyway |
Hi,
I have added a simple method to format numbers (Double, Int, Float) using a NSNumberFormatter saved as a class var in a new class ExSwiftFormatter because formatters are expensive to create.
Tell me if you are interested in this PR before merging, I will add doc and update the readme.
I have also added a NSNumberFormatter extension to set the formatter precision.
instead of
If you agree I would like to add other formatters and also unit converters