Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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(, forKey: selectedThemeKey)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment