Created
October 28, 2019 16:01
-
-
Save ericlewis/2e73e34b6c6b5fe36fb50730faf2629f to your computer and use it in GitHub Desktop.
This file contains 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
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