Mercurial > public > geoquiz
view GeoQuiz/Logic/UserClass.swift @ 13:bdfff35dd43c
implement RevenueCat
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Wed, 12 Oct 2022 11:47:29 +0200 |
parents | a793f33f05fb |
children | 136928bae534 |
line wrap: on
line source
// // UserClass.swift // GeoQuiz // // Created by Dennis Concepción Martín on 7/10/22. // import Foundation class User: ObservableObject { @Published var settings = UserSettings() { didSet { if let userSettingsEncoded = try? JSONEncoder().encode(settings) { UserDefaults.standard.set(userSettingsEncoded, forKey: "UserSettings") } } } init() { if let userSettings = UserDefaults.standard.data(forKey: "UserSettings") { if let decodedUserSettings = try? JSONDecoder().decode(UserSettings.self, from: userSettings) { settings = decodedUserSettings } } } }