Created
October 29, 2020 04:40
-
-
Save noppefoxwolf/74fd54fa8ec686f1b61dc5499b08cba1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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