Created
June 18, 2019 12:14
-
-
Save funkenstrahlen/ad68579cee6be34ae259eaf91da9b231 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// | |
// UserDefaults+PropertyWrapper.swift | |
// PodliveShared | |
// | |
// Created by Stefan Trauth on 18.06.19. | |
// Copyright © 2019 Stefan Trauth. All rights reserved. | |
// | |
import Foundation | |
@propertyWrapper | |
public struct UserDefault<T> { | |
let key: String | |
let defaultValue: T | |
private let defaults = UserDefaults(suiteName: "group.de.stefantrauth.Podlive")! | |
public init(_ key: String, defaultValue: T) { | |
self.key = key | |
self.defaultValue = defaultValue | |
} | |
public var value: T { | |
get { | |
return defaults.object(forKey: key) as? T ?? defaultValue | |
} | |
set { | |
defaults.set(newValue, forKey: key) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment