From 20c9d731403ecee57c3c05587eb6534ce410927c Mon Sep 17 00:00:00 2001 From: Kaiser Date: Tue, 18 Aug 2020 13:35:22 -0400 Subject: [PATCH] PermissionStatus conforms to codable --- .DS_Store | Bin 0 -> 6148 bytes Source/PermissionStatus.swift | 2 +- Source/Supporting Files/Utilities.swift | 13 ++++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9746ce4a4097e2d4200f5072834c0f408c2ad95a GIT binary patch literal 6148 zcmeHK!Ab)$5S`H;7DVX5gU5h(p??s|_Ac}Xq+QWU*DNiH$NY`|;WzjT{)ca7Qnk33 zB8b$PC3%yXOg4GTW)dRe@k28r8WK^3BFLijh?sj_2c`1>$U4S?)_4|_=)Py5zi5)V zpU@>;(~4Tm{B!>2^h9&4q=B!4H__elW;C6rwzGx29`6#{rn;Uj(+n}y^CZ8WJ-%G* z7T^3RzPtT0cb4z%;tV(g&VV!UPZ>bY7O9R5y>)8?*!~l#1vmq=Hwossja=Bu#g~J|7zgRFES~#)38RL{UZ!RyJlPw4BP8=^?*sHgQ9iz>PG+wvsW29zrl5$Tsjfk4+( l4AfMNhU_D!>NI~49sXD_8_FnR*KnX81e6f3oPl3p;2j~LLgWAd literal 0 HcmV?d00001 diff --git a/Source/PermissionStatus.swift b/Source/PermissionStatus.swift index 8d3b4b9..0c75cc5 100644 --- a/Source/PermissionStatus.swift +++ b/Source/PermissionStatus.swift @@ -22,7 +22,7 @@ // SOFTWARE. // -public enum PermissionStatus: String { +public enum PermissionStatus: String, Codable { case authorized = "Authorized" case denied = "Denied" case disabled = "Disabled" diff --git a/Source/Supporting Files/Utilities.swift b/Source/Supporting Files/Utilities.swift index 6dc00e5..aa4fefb 100644 --- a/Source/Supporting Files/Utilities.swift +++ b/Source/Supporting Files/Utilities.swift @@ -49,7 +49,7 @@ extension UIControl.State: Hashable { } @propertyWrapper -struct UserDefault { +struct UserDefault { let key: String let defaultValue: T @@ -60,10 +60,17 @@ struct UserDefault { var wrappedValue: T { get { - return UserDefaults.standard.object(forKey: key) as? T ?? defaultValue + if let data = UserDefaults.standard.object(forKey: key) as? Data, + let user = try? JSONDecoder().decode(T.self, from: data) { + return user + + } + return defaultValue } set { - UserDefaults.standard.set(newValue, forKey: key) + if let encoded = try? JSONEncoder().encode(newValue) { + UserDefaults.standard.set(encoded, forKey: key) + } } } }