CachingManager.swift
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
//
// FirstTimeOpen.swift
// browser
//
// Created by Artem Talko on 27.09.2023.
//
import Foundation
final class CachingManager {
private enum Keys {
static let isFirstAppLoad = "IsFirstAppLoad"
static let isAdBlocking = "IsAdBlocking"
static let expirationDate = "ExpirationDate"
static let isActive = "isActive"
}
static let shared = CachingManager()
private let userDefaults = UserDefaults.standard
private init() {}
var isFirstAppLoad: Bool {
get { return userDefaults.bool(forKey: Keys.isFirstAppLoad) }
set { userDefaults.set(newValue, forKey: Keys.isFirstAppLoad) }
}
var adBlockerState: Bool {
get { return userDefaults.bool(forKey: Keys.isAdBlocking) }
set { userDefaults.set(newValue, forKey: Keys.isAdBlocking) }
}
var expirationDate: Double? {
get {
if userDefaults.object(forKey: Keys.expirationDate) == nil {
return nil
}
return userDefaults.double(forKey: Keys.expirationDate)
}
set { userDefaults.set(newValue, forKey: Keys.expirationDate) }
}
var isSubscriptionActive: Bool {
get {
// Check if expiration date is present and greater than the current date
if let expirationDate = expirationDate, expirationDate > Date().timeIntervalSince1970 {
return true
} else {
// If expiration date is not present or has passed, set subscription to false
isSubscriptionActive = false
return false
}
}
set { userDefaults.set(newValue, forKey: Keys.isActive) }
}
}