Created
May 28, 2020 19:02
-
-
Save bermudalocket/c35e31ef3c5184a2181b1a4bedf8a6e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PlaygroundSupport | |
import SwiftUI | |
struct ContentView: View { | |
@State private var userQuestions: [String] = [ | |
"one", "two" | |
] | |
var body: some View { | |
NavigationView { | |
List { | |
ForEach(self.userQuestions, id: \.self) { question in | |
NavigationLink(destination: DetailView(userQuestions: self.$userQuestions, question: question)) { | |
Text(question) | |
} | |
} | |
} | |
} | |
} | |
} | |
struct DetailView: View { | |
@Environment(\.presentationMode) var presentationMode | |
@Binding var userQuestions: [String] | |
let question: String | |
var body: some View { | |
HStack { | |
Text(self.question) | |
Button(action: { | |
self.userQuestions.removeAll { $0 == self.question } | |
self.presentationMode.wrappedValue.dismiss() | |
}, label: { | |
Text("Answer") | |
}) | |
} | |
} | |
} | |
PlaygroundSupport.PlaygroundPage.current.liveView = UIHostingController(rootView: ContentView()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment