Skip to content

Instantly share code, notes, and snippets.

@Otbivnoe
Created March 16, 2018 06:33
Show Gist options
  • Save Otbivnoe/ccad2ed0fedd5f8d712ba360b9e04c0a to your computer and use it in GitHub Desktop.
Save Otbivnoe/ccad2ed0fedd5f8d712ba360b9e04c0a to your computer and use it in GitHub Desktop.
extension UserDefaults {
subscript<T>(key: String) -> T? {
get {
return value(forKey: key) as? T
}
set {
set(newValue, forKey: key)
}
}
}
class SettingsService {
var isNotificationsEnabled: Bool {
get {
return UserDefaults.standard[#function] ?? true
}
set {
UserDefaults.standard[#function] = newValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment