Guest User

Untitled

a guest
May 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. extension UserDefaults {
  2.  
  3. func setCodable<T: Encodable>(_ value: T, forKey key: String) throws {
  4. let data = try PropertyListEncoder().encode(value)
  5. set(data, forKey: key)
  6. }
  7.  
  8. func codable<T: Decodable>(forKey key: String) throws -> T? {
  9. guard let data = self.data(forKey: key) else { return nil }
  10. return try PropertyListDecoder().decode(T.self, from: data)
  11. }
  12. }
Add Comment
Please, Sign In to add comment