Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PermissionStatus conforms to codable #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/PermissionStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// SOFTWARE.
//

public enum PermissionStatus: String {
public enum PermissionStatus: String, Codable {
case authorized = "Authorized"
case denied = "Denied"
case disabled = "Disabled"
Expand Down
13 changes: 10 additions & 3 deletions Source/Supporting Files/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension UIControl.State: Hashable {
}

@propertyWrapper
struct UserDefault<T> {
struct UserDefault<T: Codable> {
let key: String
let defaultValue: T

Expand All @@ -60,10 +60,17 @@ struct UserDefault<T> {

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)
}
}
}
}
Expand Down