Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
//
2
//  PreferenceModel.swift
3
//  twogetskills
4
//
5
//  Created by Efrain Yanez Recanatini on 3/3/22.
6
//
7
 
8
import Foundation
9
 
10
 
11
class Preference {
12
    let standardPreference = UserDefaults.standard
13
 
14
    var deviceUuid : String
15
    var userUuid : String
16
    var fcmToken : String
17
    var email : String
18
    var firstName : String
19
    var lastName : String
20
    var image : String
21
    var password : String
22
    var aes : String
23
    var maxDateChanges : String
24
    var viewIdxActive: Int
25
    var topicUuidActive : String
26
    var capsuleUuidActive : String
27
    var slideUuidActive : String
28
    var companyUuidActive : String
29
    var companyCount : Int
30
    var capsuleUuidOld : String
31
 
32
    static let sharedInstance: Preference = {
33
           let instance = Preference()
34
           // setup code
35
           return instance
36
    }()
37
 
38
    private init() {
39
        self.deviceUuid = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_DEVICE_ID) ?? ""
40
        self.userUuid = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_USER_ID) ?? ""
41
        self.fcmToken = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_FCM_TOKEN) ?? ""
42
        self.email = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_EMAIL) ?? ""
43
        self.firstName = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_FIRST_NAME) ?? ""
44
        self.lastName = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_LAST_NAME) ?? ""
45
        self.image = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_IMAGE) ?? ""
46
        self.password = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_PASSWORD) ?? ""
47
        self.aes = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_AES) ?? ""
48
        self.maxDateChanges = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_MAX_DATE_CHANGES) ?? ""
49
        self.viewIdxActive = standardPreference.integer(forKey: Constants.PREFERENCE_FIELD_VIEW_IDX_ACTIVE)
50
        self.topicUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_TOPIC_UUID_ACTIVE) ?? ""
51
        self.capsuleUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_CAPSULE_UUID_ACTIVE) ?? ""
52
        self.slideUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_SLIDE_UUID_ACTIVE) ?? ""
53
        self.companyUuidActive = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_COMPANY_UUID_ACTIVE) ?? ""
54
        self.companyCount = standardPreference.integer(forKey: Constants.PREFERENCE_FIELD_COMPANY_COUNT) ?? 0
55
        self.capsuleUuidOld = standardPreference.string(forKey: Constants.PREFERENCE_FIELD_CAPSULE_UUID_OLD) ?? ""
56
    }
57
 
58
    func save() -> Void {
59
        standardPreference.setValue(deviceUuid, forKey: Constants.PREFERENCE_FIELD_DEVICE_ID)
60
        standardPreference.setValue(userUuid, forKey: Constants.PREFERENCE_FIELD_USER_ID)
61
        standardPreference.setValue(fcmToken, forKey: Constants.PREFERENCE_FIELD_FCM_TOKEN)
62
        standardPreference.setValue(email, forKey: Constants.PREFERENCE_FIELD_EMAIL)
63
        standardPreference.setValue(firstName, forKey: Constants.PREFERENCE_FIELD_FIRST_NAME)
64
        standardPreference.setValue(lastName, forKey: Constants.PREFERENCE_FIELD_LAST_NAME)
65
        standardPreference.setValue(image, forKey: Constants.PREFERENCE_FIELD_IMAGE)
66
        standardPreference.setValue(password, forKey: Constants.PREFERENCE_FIELD_PASSWORD)
67
        standardPreference.setValue(aes, forKey: Constants.PREFERENCE_FIELD_AES)
68
        standardPreference.setValue(maxDateChanges, forKey: Constants.PREFERENCE_FIELD_MAX_DATE_CHANGES)
69
        standardPreference.setValue(viewIdxActive, forKey: Constants.PREFERENCE_FIELD_VIEW_IDX_ACTIVE)
70
        standardPreference.setValue(topicUuidActive, forKey: Constants.PREFERENCE_FIELD_TOPIC_UUID_ACTIVE)
71
        standardPreference.setValue(capsuleUuidActive, forKey: Constants.PREFERENCE_FIELD_CAPSULE_UUID_ACTIVE)
72
        standardPreference.setValue(slideUuidActive, forKey: Constants.PREFERENCE_FIELD_SLIDE_UUID_ACTIVE)
73
        standardPreference.setValue(companyUuidActive, forKey: Constants.PREFERENCE_FIELD_COMPANY_UUID_ACTIVE)
74
        standardPreference.setValue(companyCount, forKey: Constants.PREFERENCE_FIELD_COMPANY_COUNT)
75
        standardPreference.setValue(capsuleUuidOld, forKey: Constants.PREFERENCE_FIELD_CAPSULE_UUID_OLD)
76
        standardPreference.synchronize()
77
    }
78
}