I'm using XCode 15.0.1 (Swift 5.9)
I tried other TextField formats (ParseableFormatStyle). I couldn't get them to work except USD currency. According to Apple's documentation, it is a "Beta Software". Why is it in the production version?
For the .percent format, I think the TextField is expecting a binding variable with a Decimal type. However, I can't even declare a simple Decimal type variable. Here is an example
private var pct2: Decimal = Decimal(1)
XCode shows an "Argument passed to call that takes no arguments". That's strange. According to Apple's documentation, Decimal should have an Int initializer.
If the TextField format property is a functional feature, perhaps the documentation should provide more information and examples.
I ended up using the TextField formatter property with a NumberFormatter. for all number input, such as percent, currency, and number. I haven't type of Formatter yet. Just like @Hean20, I put the currency symbol and percentage sign outside the TextField.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: