//
//  UserDefault.swift
//  USB Meter
//
//  Created by Bogdan Timofte on 03/03/2020.
//  Copyright © 2020 Bogdan Timofte. All rights reserved.
//

import Foundation

@propertyWrapper struct UserDefault<T> {
    let key: String
    let defaultValue: T
    
    var wrappedValue: T {
        get {
            return UserDefaults.standard.object(forKey: key) as? T ?? defaultValue
        }
        set {
            UserDefaults.standard.set(newValue, forKey: key)
        }
    }

//    static func getValue(forKey: String) -> T? {
//        return UserDefaults.standard.object(forKey: forKey) as? T
//    }
}

// Asta cel mai probabil face figuri pentru ca nu pare sa aiba observer
@propertyWrapper struct UserRuntime<T> {
    
    var value: T

    var wrappedValue: T {
        get {
            return value
        }
        set {
            value = newValue
        }
    }

}
