comparison GeoQuiz/Logic/UserClass.swift @ 10:a793f33f05fb

refactor code and fix layout
author Dennis C. M. <dennis@denniscm.com>
date Sat, 08 Oct 2022 21:36:40 +0200
parents GeoQuiz/Logic/User.swift@3540c7efc216
children 136928bae534
comparison
equal deleted inserted replaced
9:3540c7efc216 10:a793f33f05fb
1 //
2 // UserClass.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 = UserSettings() {
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(UserSettings.self, from: userSettings) {
23 settings = decodedUserSettings
24 }
25 }
26 }
27 }