Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension UserDefaults {
- func setCodable<T: Encodable>(_ value: T, forKey key: String) throws {
- let data = try PropertyListEncoder().encode(value)
- set(data, forKey: key)
- }
- func codable<T: Decodable>(forKey key: String) throws -> T? {
- guard let data = self.data(forKey: key) else { return nil }
- return try PropertyListDecoder().decode(T.self, from: data)
- }
- }
Add Comment
Please, Sign In to add comment