Skip to content

Instantly share code, notes, and snippets.

@GeekAndDad
Created December 22, 2019 18:44
Show Gist options
  • Save GeekAndDad/380cc45d03f23a7f0fea6e8b2f122a3d to your computer and use it in GitHub Desktop.
Save GeekAndDad/380cc45d03f23a7f0fea6e8b2f122a3d to your computer and use it in GitHub Desktop.
// point free video 65 at the 14:50 point.
// https://www.pointfree.co/episodes/ep65-swiftui-and-state-management-part-1#t887
//
// This code has an issue whereby a navigation link cannot be activated twice unless
// the other navigation link is actived in between the two activations of a particular
// link.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List {
NavigationLink(destination: CounterView()) {
Text("Counter demo")
}
NavigationLink(destination: EmptyView()) {
Text("Favorite primes")
}
}
.navigationBarTitle("State management")
}
}
}
struct CounterView: View {
var body: some View {
VStack {
HStack {
Button( action: {}) {
Text("-")
}
Text("0")
Button( action: {}) {
Text("+")
}
}
Button( action: {}) {
Text("Is this prime?")
}
Button( action: {}) {
Text("What is the 0th prime?")
}
}
.font(.title)
.navigationBarTitle("Counter demo")
}
}
import PlaygroundSupport
PlaygroundPage.current.liveView = UIHostingController(
// rootView: CounterView()
rootView: ContentView()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment