Browse Source

Update DataStore.swift

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
2bd95b1e21
  1. 7
      Clocker/Overall App/DataStore.swift

7
Clocker/Overall App/DataStore.swift

@ -23,6 +23,7 @@ enum ViewType {
class DataStore: NSObject {
private static var sharedStore = DataStore(with: UserDefaults.standard)
private var userDefaults: UserDefaults!
private var defaultUbiquotousKeyValueStore: NSUbiquitousKeyValueStore!
// Since these pref can accessed every second, let's cache this
private var shouldDisplayDayInMenubar: Bool = false
@ -35,12 +36,13 @@ class DataStore: NSObject {
init(with defaults: UserDefaults) {
super.init()
userDefaults = defaults
defaultUbiquotousKeyValueStore = NSUbiquitousKeyValueStore.default
shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar)
shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar)
}
func timezones() -> [Data] {
if let cloudPreferences = NSUbiquitousKeyValueStore().object(forKey: CLDefaultPreferenceKey) as? [Data] {
if let cloudPreferences = defaultUbiquotousKeyValueStore.object(forKey: CLDefaultPreferenceKey) as? [Data] {
Logger.info("Returning preferences from NSUbiquitousKeyValueStore")
return cloudPreferences
}
@ -55,8 +57,7 @@ class DataStore: NSObject {
func setTimezones(_ timezones: [Data]?) {
userDefaults.set(timezones, forKey: CLDefaultPreferenceKey)
// iCloud sync
NSUbiquitousKeyValueStore().set(timezones, forKey: CLDefaultPreferenceKey)
NSUbiquitousKeyValueStore().synchronize()
defaultUbiquotousKeyValueStore.set(timezones, forKey: CLDefaultPreferenceKey)
}
func menubarTimezones() -> [Data]? {

Loading…
Cancel
Save