Add docs
A SwiftUI alert with text field(s) for iOS 13 and greater.
As Apple is going to introduce text field(s) as an alert actions in iOS 16, this is a good replacement for older versions.
You can add TextFieldAlert to an Xcode project by adding it as a package dependency.
https://github.com/sochalewski/TextFieldAlert
TextFieldAlert is exposed through View extension:
View
func textFieldAlert( title: String?, message: String?, textFields: [TextFieldAlert.TextField], actions: [TextFieldAlert.Action], isPresented: Binding<Bool> )
You can use it in your code as follows:
struct ExampleView: View { @State var isPresented = false @State var text1 = "" @State var text2 = "" var body: some View { VStack { Button { isPresented = true } label: { Text("Alert") } Text(text1) Text(text2) } .textFieldAlert( title: "Title", message: "Message", textFields: [ .init(text: $text1), .init(text: $text2) ], actions: [ .init(title: "OK") ], isPresented: $isPresented ) } }
More advanced usage (incl. moving the responsibility to a view model, some customization and enabling action buttons conditionally) is available in the Example app.
Piotr Sochalewski, sochalewski.github.io
TextFieldAlert is heavily inspired by tanzolone‘s answer on StackOverflow.
TextFieldAlert is available under the MIT license. See the LICENSE file for more info.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
TextFieldAlert
A SwiftUI alert with text field(s) for iOS 13 and greater.
As Apple is going to introduce text field(s) as an alert actions in iOS 16, this is a good replacement for older versions.
Requirements
Installation
You can add TextFieldAlert to an Xcode project by adding it as a package dependency.
https://github.com/sochalewski/TextFieldAlert
into the package repository URL text field.Usage
TextFieldAlert is exposed through
View
extension:You can use it in your code as follows:
More advanced usage (incl. moving the responsibility to a view model, some customization and enabling action buttons conditionally) is available in the Example app.
Author
Piotr Sochalewski, sochalewski.github.io
TextFieldAlert is heavily inspired by tanzolone‘s answer on StackOverflow.
License
TextFieldAlert is available under the MIT license. See the LICENSE file for more info.