Mercurial > public > geoquiz
comparison GeoQuiz/Models/Controllers/UserController.swift @ 26:425078c01194
refactor code
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 09 Nov 2022 10:30:01 +0100 |
parents | GeoQuiz/Logic/UserController.swift@f140bb277c96 |
children |
comparison
equal
deleted
inserted
replaced
25:b3df0f5dc750 | 26:425078c01194 |
---|---|
1 // | |
2 // UserController.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 7/10/22. | |
6 // | |
7 | |
8 import Foundation | |
9 | |
10 class UserController: ObservableObject { | |
11 @Published var data = UserDataModel() { | |
12 didSet { | |
13 if let userDataEncoded = try? JSONEncoder().encode(data) { | |
14 UserDefaults.standard.set(userDataEncoded, forKey: "UserData") | |
15 } | |
16 } | |
17 } | |
18 | |
19 init() { | |
20 if let userData = UserDefaults.standard.data(forKey: "UserData") { | |
21 if let decodedUserData = try? JSONDecoder().decode(UserDataModel.self, from: userData) { | |
22 data = decodedUserData | |
23 } | |
24 } | |
25 } | |
26 } |