Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SharedDefaults Property Wrapper
struct SharedDefault<T> {
let key: String
let defaultValue: T
var wrappedValue: T {
get {
UserDefaults.securityCard.object(forKey: key) as? T ?? defaultValue
set {
UserDefaults.securityCard.set(newValue, forKey: key)
extension UserDefaults {
static let securityCard = UserDefaults(suiteName: "...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment