Skip to content

Commit 801999e

Browse files
committed
Add forceSync for better behavior control
1 parent 4b4e6cf commit 801999e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Sources/Defaults+Syncing.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public extension DefaultsAdapter {
3636
syncer.syncedKeys.subtract(rawKeys)
3737
}
3838

39+
func forceSync() {
40+
syncer.forceSync()
41+
}
42+
3943
func stopSyncingAll() {
4044
syncer.syncedKeys = []
4145
}

Sources/DefaultsSyncer.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ internal class DefaultsSyncer {
2929

3030
let defaults: UserDefaults
3131

32-
var syncedKeys = Set<String>() {
33-
didSet { iCloudDefaultsDidUpdate() }
34-
}
32+
var syncedKeys = Set<String>()
3533

3634
init(defaults: UserDefaults) {
3735
self.defaults = defaults
@@ -43,6 +41,11 @@ internal class DefaultsSyncer {
4341
name: UserDefaults.didChangeNotification)
4442
}
4543

44+
internal func forceSync() {
45+
iCloudDefaultsDidUpdate()
46+
localDefaultsDidUpdate()
47+
}
48+
4649
@objc
4750
private func iCloudDefaultsDidUpdate() {
4851
guard !syncedKeys.isEmpty else { return }

0 commit comments

Comments
 (0)