AutorÃa | Ultima modificación | Ver Log |
//
// PreferenceModel.swift
// twogetskills
//
// Created by Efrain Yanez Recanatini on 3/3/22.
//
import Foundation
class Preference {
let standardPreference = UserDefaults.standard
var deviceUuid : String
var userUuid : String
var fcmToken : String
var email : String
var firstName : String
var lastName : String
var image : String
var password : String
var aes : String
var maxDateChanges : String
var viewIdxActive: Int
var topicUuidActive : String
var capsuleUuidActive : String
var slideUuidActive : String
var companyUuidActive : String
var companyCount : Int
var capsuleUuidOld : String
static let sharedInstance: Preference = {
let instance = Preference()
// setup code
return instance
}()
private init() {
self.deviceUuid = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_DEVICE_ID) ?? ""
self.userUuid = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_USER_ID) ?? ""
self.fcmToken = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_FCM_TOKEN) ?? ""
self.email = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_EMAIL) ?? ""
self.firstName = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_FIRST_NAME) ?? ""
self.lastName = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_LAST_NAME) ?? ""
self.image = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_IMAGE) ?? ""
self.password = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_PASSWORD) ?? ""
self.aes = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_AES) ?? ""
self.maxDateChanges = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_MAX_DATE_CHANGES) ?? ""
self.viewIdxActive = standardPreference.integer(forKey: Constants.PREFERENCE_FIELD_VIEW_IDX_ACTIVE)
self.topicUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_TOPIC_UUID_ACTIVE) ?? ""
self.capsuleUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_CAPSULE_UUID_ACTIVE) ?? ""
self.slideUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_SLIDE_UUID_ACTIVE) ?? ""
self.companyUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_COMPANY_UUID_ACTIVE) ?? ""
self.companyCount = standardPreference.integer(forKey: Constants.PREFERENCE_FIELD_COMPANY_COUNT) ?? 0
self.capsuleUuidOld = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_CAPSULE_UUID_OLD) ?? ""
}
func save() -> Void {
standardPreference.setValue(deviceUuid, forKey: Constants.PREFERENCE_FIELD_DEVICE_ID)
standardPreference.setValue(userUuid, forKey: Constants.PREFERENCE_FIELD_USER_ID)
standardPreference.setValue(fcmToken, forKey: Constants.PREFERENCE_FIELD_FCM_TOKEN)
standardPreference.setValue(email, forKey: Constants.PREFERENCE_FIELD_EMAIL)
standardPreference.setValue(firstName, forKey: Constants.PREFERENCE_FIELD_FIRST_NAME)
standardPreference.setValue(lastName, forKey: Constants.PREFERENCE_FIELD_LAST_NAME)
standardPreference.setValue(image, forKey: Constants.PREFERENCE_FIELD_IMAGE)
standardPreference.setValue(password, forKey: Constants.PREFERENCE_FIELD_PASSWORD)
standardPreference.setValue(aes, forKey: Constants.PREFERENCE_FIELD_AES)
standardPreference.setValue(maxDateChanges, forKey: Constants.PREFERENCE_FIELD_MAX_DATE_CHANGES)
standardPreference.setValue(viewIdxActive, forKey: Constants.PREFERENCE_FIELD_VIEW_IDX_ACTIVE)
standardPreference.setValue(topicUuidActive, forKey: Constants.PREFERENCE_FIELD_TOPIC_UUID_ACTIVE)
standardPreference.setValue(capsuleUuidActive, forKey: Constants.PREFERENCE_FIELD_CAPSULE_UUID_ACTIVE)
standardPreference.setValue(slideUuidActive, forKey: Constants.PREFERENCE_FIELD_SLIDE_UUID_ACTIVE)
standardPreference.setValue(companyUuidActive, forKey: Constants.PREFERENCE_FIELD_COMPANY_UUID_ACTIVE)
standardPreference.setValue(companyCount, forKey: Constants.PREFERENCE_FIELD_COMPANY_COUNT)
standardPreference.setValue(capsuleUuidOld, forKey: Constants.PREFERENCE_FIELD_CAPSULE_UUID_OLD)
standardPreference.synchronize()
}
}