diff --git a/Clocker/Overall App/DataStore.swift b/Clocker/Overall App/DataStore.swift index 7cf5f40..bce8b24 100644 --- a/Clocker/Overall App/DataStore.swift +++ b/Clocker/Overall App/DataStore.swift @@ -44,7 +44,10 @@ class DataStore: NSObject { userDefaults = defaults shouldDisplayDayInMenubar = shouldDisplay(.dayInMenubar) shouldDisplayDateInMenubar = shouldDisplay(.dateInMenubar) - + setupSyncNotification() + } + + func setupSyncNotification() { if shouldDisplay(.sync) { ubiquitousStore = NSUbiquitousKeyValueStore.default NotificationCenter.default.addObserver(self, @@ -52,6 +55,10 @@ class DataStore: NSObject { name: NSUbiquitousKeyValueStore.didChangeExternallyNotification, object: NSUbiquitousKeyValueStore.default) ubiquitousStore?.synchronize() + } else { + NotificationCenter.default.removeObserver(self, + name: NSUbiquitousKeyValueStore.didChangeExternallyNotification, + object: nil) } } diff --git a/Clocker/Preferences/Appearance/AppearanceViewController.swift b/Clocker/Preferences/Appearance/AppearanceViewController.swift index 5730ff6..04b66a3 100644 --- a/Clocker/Preferences/Appearance/AppearanceViewController.swift +++ b/Clocker/Preferences/Appearance/AppearanceViewController.swift @@ -359,8 +359,8 @@ class AppearanceViewController: ParentViewController { previewPanelTableView.reloadData() } - @IBAction func toggleSync(_: Any) { - print("Toggle Sync") + @IBAction func toggleSync(_ sender: NSSegmentedControl) { + DataStore.shared().setupSyncNotification() } }