Unfortunately, .currency and .currencyISOCode return "XXX" instead of an actual currency symbol or code (see NumberFormatter.Style in the Apple Developer documentation). Do you have an idea, why this occurs? Note that I changed the formatter locale from "en" (which is returned by Locale.current) to "de", but that still returns "XXX".
import SwiftUI
import Foundation
struct ExpenseRow: View {
var body: some View {
Text(amountAsCurrency())
}
fileprivate func amountAsCurrency() -> String {
let str = "\(format: 35.6689, using: .currency)"
print(str)
return str
}
}
// https://www.hackingwithswift.com/articles/178/super-powered-string-interpolation-in-swift-5-0
extension String.StringInterpolation {
mutating func appendInterpolation(format value: Float, using style: NumberFormatter.Style) {
let formatter = NumberFormatter()
//print("formatter.locale = \(formatter.locale!)")
//print("Locale.current = \(Locale.current)")
formatter.locale = Locale(identifier: "de")
formatter.numberStyle = style
if let result = formatter.string(from: value as NSNumber) {
appendLiteral(result)
}
}
}