<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/TextField/init(_:value:formatter:)-4013v",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI9TextFieldVA2A0C0VRszrlE_5value9formatterACyAEGqd___AA7BindingVyqd_0_GSo11NSFormatterCtcSyRd__r0_lufc"
  },
  "title" : "init(_:value:formatter:)"
}
-->

# init(_:value:formatter:)

Create an instance which binds over an arbitrary type, `V`.

```
@export(implementation) nonisolated init<S, V>(_ title: S, value: Binding<V>, formatter: Formatter) where S : StringProtocol
```

## Parameters

`title`

The title of the text view, describing its purpose.

`value`

The underlying value to edit.

`formatter`

A formatter to use when converting between the
string the user edits and the underlying value of type `V`.
If `formatter` can’t perform the conversion, the text field doesn’t
modify `binding.value`.

## Discussion

Use this initializer to create a text field that binds to a bound optional
value, using a
<doc://com.apple.documentation/documentation/Foundation/Formatter>
to convert to and from this type. Changes to the bound value update
the string displayed by the text field. Editing the text field
updates the bound value, as long as the formatter can parse the
text. If the format style can’t parse the input, the bound value
remains unchanged.

Use the `View/onSubmit(of:_:)` modifier to invoke an action
whenever the user submits this text field.

The following example uses a
<doc://com.apple.documentation/documentation/Swift/Double>
as the bound value, and a
<doc://com.apple.documentation/documentation/Foundation/NumberFormatter>
instance to convert to and from a string representation. The formatter
uses the
<doc://com.apple.documentation/documentation/Foundation/NumberFormatter/Style/decimal>
style, to allow entering a fractional part. As the user types, the bound
value updates, which in turn updates three `Text` views that use
different format styles. If the user enters text that doesn’t represent
a valid `Double`, the bound value doesn’t update.

```
@State private var myDouble: Double = 0.673
@State private var numberFormatter: NumberFormatter = {
    var nf = NumberFormatter()
    nf.numberStyle = .decimal
    return nf
}()

var body: some View {
    VStack {
        TextField(
            value: $myDouble,
            formatter: numberFormatter
        ) {
            Text("Double")
        }
        Text(myDouble, format: .number)
        Text(myDouble, format: .number.precision(.significantDigits(5)))
        Text(myDouble, format: .number.notation(.scientific))
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)