Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Binding example
struct NameDisplayView: View {
@State var name: String = "unknown"
@State var showNameChange = false
var body: some View {
VStack {
Text("Your name is \(name)")
Divider()
Button("Change") {
self.showNameChange = true
}
}
.sheet(isPresented: $showNameChange) {
NameChangeView(text: self.$name)
}
}
}
struct NameChangeView: View {
@Environment(\.presentationMode) var presentationMode
@Binding var text: String
var body: some View {
TextField("Type Here", text: $text, onCommit: { self.presentationMode.wrappedValue.dismiss() })
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.