CachingManager.swift 1.11 KB
//
//  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 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) }
    }
}