Last active
June 13, 2018 09:54
-
-
Save tiagomartinho/a64c89b68dfff8be96bf10f96f82f81c to your computer and use it in GitHub Desktop.
DefaultsThemeRepository
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
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