Skip to content

Instantly share code, notes, and snippets.

@noppefoxwolf
Created October 29, 2020 04:40
Show Gist options
  • Save noppefoxwolf/74fd54fa8ec686f1b61dc5499b08cba1 to your computer and use it in GitHub Desktop.
Save noppefoxwolf/74fd54fa8ec686f1b61dc5499b08cba1 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@ObservedObject var vm: VM = .init()
var body: some View {
NavigationView {
List(vm.items, rowContent: { (item) in
NavigationLink(
destination: DestinationView(vm: vm),
label: {
Text(item)
}
)
})
}
}
}
struct DestinationView: View {
@ObservedObject var vm: VM
var body: some View {
Button(action: {
vm.items = []
}, label: {
Text("Clear")
})
}
}
class VM: ObservableObject {
@Published var items: [String] = ["a","b"]
}
extension String: Identifiable {
public var id: String { self }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment