title: Currency Textfield in SwiftUI
body: <p>How would I create a textfield for entering currency amount that would persist the “$” symbol? Essentially making it non deletable/interactable as a string?</p>
  <p>Also as soon as I tap the textfield to enter an amount, I shouldn't have to manually delete the 0s. They should automatically clear unless there is an actual amount</p>
  <p>Current Code:</p>
  <pre><code>struct CurrencyField: View {
      @State private var amount = 0.00
      
      private let numberFormatter: NumberFormatter
      
      init() {
          numberFormatter = NumberFormatter()
          numberFormatter.numberStyle = .currency
          numberFormatter.maximumFractionDigits = 2
      }
      
      var body: some View {
          TextField(&quot;$0.00&quot;, value: $amount, formatter: numberFormatter)
              .font(.system(size: 45, weight: .bold))
              .foregroundColor(.primary)
              .padding(.vertical, 1)
              .keyboardType(.decimalPad)
              .multilineTextAlignment(.center)
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/9jAma.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9jAma.gif" alt="enter image description here" /></a></p>