Skip to content

Instantly share code, notes, and snippets.

@bermudalocket
Created May 28, 2020 19:02
Show Gist options
  • Save bermudalocket/c35e31ef3c5184a2181b1a4bedf8a6e9 to your computer and use it in GitHub Desktop.
Save bermudalocket/c35e31ef3c5184a2181b1a4bedf8a6e9 to your computer and use it in GitHub Desktop.
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