---
title: "init(_:text:onCommit:)"
framework: swiftui
role: symbol
role_heading: Initializer
path: "swiftui/textfield/init(_:text:oncommit:)"
---

# init(_:text:onCommit:)

Creates a text field with a text label generated from a localized title string.

## Declaration

```swift
nonisolated init(_ titleKey: LocalizedStringKey, text: Binding<String>, onCommit: @escaping () -> Void)
```

## Parameters

- `titleKey`: The key for the localized title of the text field, describing its purpose.
- `text`: The text to display and edit.
- `onCommit`: An action to perform when the user performs an action (for example, when the user presses the Return key) while the text field has focus.

## See Also

### Creating a text field with a string

- [init(_:text:onEditingChanged:onCommit:)](swiftui/textfield/init(_:text:oneditingchanged:oncommit:).md)
- [init(_:text:onEditingChanged:)](swiftui/textfield/init(_:text:oneditingchanged:).md)
