Skip to content

Instantly share code, notes, and snippets.

@tiagomartinho
Last active June 13, 2018 09:54
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 tiagomartinho/a64c89b68dfff8be96bf10f96f82f81c to your computer and use it in GitHub Desktop.
Save tiagomartinho/a64c89b68dfff8be96bf10f96f82f81c to your computer and use it in GitHub Desktop.
DefaultsThemeRepository
import Foundation
class DefaultsThemeRepository: ThemeRepository {
private let selectedThemeKey = "selectedThemeKey"
private let defaults = UserDefaults.standard
func load() -> Theme {
if let storedTheme = defaults.string(forKey: selectedThemeKey),
let theme = ThemeName(rawValue: storedTheme)?.theme {
return theme
} else {
return DarkTheme()
}
}
func save(_ theme: Theme) {
defaults.setValue(theme.name.rawValue, forKey: selectedThemeKey)
defaults.synchronize()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment