UserDefaultsHelper.swift 1.45 KB
Newer Older
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
//
//  UserDefaultsHelper.swift
//  App16
//
//  Created by Grigor Aghabalyan on 3/25/20.
//  Copyright © 2020 X-TECH. All rights reserved.
//

import UIKit

enum UDAliases: String {
    
    case AuthToken = "auth_token"
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
14
15
16
17
    case firstName
    case lstName
    case middleName
    case deviceToken
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
18
19
    case locale = "hy"
    case langauge = "Հայերեն"
Grigor Aghabalyan's avatar
Grigor Aghabalyan committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
}

class UserDefaultsHelper {
    
    static func isNil(_ alias: UDAliases) -> Bool {
        return UserDefaults.standard.string(forKey: alias.rawValue) == nil
    }
    
    static func getString(for alias: UDAliases) -> String? {
        return UserDefaults.standard.string(forKey: alias.rawValue)
    }
    
    static func get(alias: UDAliases) -> Any? {
        return UserDefaults.standard.string(forKey: alias.rawValue)
    }
    
    static func boolFor(alias: UDAliases) -> Bool? {
        return UserDefaults.standard.bool(forKey: alias.rawValue)
    }
    
    static func set(alias: UDAliases, value: String) {
        UserDefaults.standard.set(value, forKey: alias.rawValue)
    }
    
    static func set(alias: UDAliases, value: Any?) {
        UserDefaults.standard.set(value, forKey: alias.rawValue)
    }
    
    static func remove(alias: UDAliases) {
        UserDefaults.standard.removeObject(forKey: alias.rawValue)
    }
    
    static func remove(aliases: UDAliases...) {
        aliases.forEach { (alias) in
            UserDefaults.standard.removeObject(forKey: alias.rawValue)
        }
    }
}