Skip to content

Instantly share code, notes, and snippets.

@gahntpo
Last active June 21, 2020 09:54
Show Gist options
  • Save gahntpo/060ea809b642ece68976dd8202eb6b4e to your computer and use it in GitHub Desktop.
Save gahntpo/060ea809b642ece68976dd8202eb6b4e to your computer and use it in GitHub Desktop.
storing information of the onboarding in the NavigationController
import Foundation
import Combine
class NavigationController: ObservableObject {
@Published var hasSeenOnboarding: Bool
var subscriptions = Set<AnyCancellable>()
init() {
//initilizing by looking up the value from UserDefaults
hasSeenOnboarding = UserDefaults.standard.bool(forKey: onboardingKey)
//updating the value in UserDefaults every time the onboarding value changes
$hasSeenOnboarding.removeDuplicates().sink { (value) in
UserDefaults.standard.set(value, forKey: self.onboardingKey)
}.store(in: &subscriptions)
}
private let onboardingKey = "hasSeenOnboarding"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment