I have a program that have two libraries. One is in Objective-C and one is in Swift.
From my webserver I get format mask and set the format mask in first and second library.
I first library NSNumberFormatter
is used so expected format mask is :
#.#0 mm
But in second, that was updated to swift, they use now String.init(format:), so expected format is:
%1.2f mm
Why swift use different format mask and how to convert one to another?
You cannot convert one to the other. You should probably raise an issue with the authors of the library because it's a breaking change.
NSNumberFormatter
uses a completely different set of rules than String(format:)
. Also, NumberFormatter
is localized. The decimal point .
is a pattern to choose either .
or ,
depending on user locale. The .
in String(format:)
is a literal .
.
Nothing to do with Swift or Obj-C. Both APIs are available in both languages.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.