Skip to content

Instantly share code, notes, and snippets.

Last active April 28, 2020 23:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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)")
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() })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment