9
|
1 //
|
|
2 // User.swift
|
|
3 // GeoQuiz
|
|
4 //
|
|
5 // Created by Dennis Concepción Martín on 7/10/22.
|
|
6 //
|
|
7
|
|
8 import Foundation
|
|
9
|
|
10 class User: ObservableObject {
|
|
11 @Published var settings = UserSettingsModel() {
|
|
12 didSet {
|
|
13 if let userSettingsEncoded = try? JSONEncoder().encode(settings) {
|
|
14 UserDefaults.standard.set(userSettingsEncoded, forKey: "UserSettings")
|
|
15 }
|
|
16 }
|
|
17 }
|
|
18
|
|
19
|
|
20 init() {
|
|
21 if let userSettings = UserDefaults.standard.data(forKey: "UserSettings") {
|
|
22 if let decodedUserSettings = try? JSONDecoder().decode(UserSettingsModel.self, from: userSettings) {
|
|
23 settings = decodedUserSettings
|
|
24 }
|
|
25 }
|
|
26 }
|
|
27 }
|