BlueWallet/ios/Shared/UserDefaultsExtension.swift
2024-04-14 12:51:09 -04:00

19 lines
533 B
Swift

//
// UserDefaultsExtension.swift
// BlueWallet
//
// Created by Marcos Rodriguez on 2/8/21.
// Copyright © 2021 BlueWallet. All rights reserved.
//
import Foundation
extension UserDefaults {
func codable<Element: Codable>(forKey key: String) -> Element? {
guard let userDefaults = UserDefaults(suiteName: UserDefaultsGroupKey.GroupName.rawValue), let data = userDefaults.data(forKey: key) else { return nil }
let element = try? PropertyListDecoder().decode(Element.self, from: data)
return element
}
}