Skip to content

Instantly share code, notes, and snippets.

@ericlewis
Created October 28, 2019 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericlewis/2e73e34b6c6b5fe36fb50730faf2629f to your computer and use it in GitHub Desktop.
Save ericlewis/2e73e34b6c6b5fe36fb50730faf2629f to your computer and use it in GitHub Desktop.
class Store: ObservableObject {
@Published var id: String? = nil
init() {
id = UserDefaults.standard.string(forKey: "key")
let _ = $id.sink {
UserDefaults.standard.set(id, forKey: "key")
}
}
}
class Example: View {
@ObservedObject var store = Store()
var body: some View {
NavigationView {
NavigationLink(destination: Text(id ?? ""), tag: "test", selection: $store.id) {
Text("Press me")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment