Skip to content

Commit

Permalink
Add notification observe when iCloudStore is used
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLeif committed Dec 7, 2023
1 parent 9802f01 commit 8a018f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
9 changes: 0 additions & 9 deletions Sources/AppState/Application/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ open class Application: NSObject, ObservableObject {
loadDefaultDependencies()

consume(object: cache)

if #available(iOS 15.0, watchOS 9.0, macOS 11.0, tvOS 15.0, *) {
NotificationCenter.default.addObserver(
self,
selector: #selector(didChangeExternally),
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: NSUbiquitousKeyValueStore.default
)
}
}

@objc @available(iOS 15.0, watchOS 9.0, macOS 11.0, tvOS 15.0, *)
Expand Down
11 changes: 10 additions & 1 deletion Sources/AppState/Application/Types/Application+SyncState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import Foundation
extension Application {
/// The default `NSUbiquitousKeyValueStore` instance.
public var icloudStore: Dependency<NSUbiquitousKeyValueStore> {
dependency(NSUbiquitousKeyValueStore.default)
dependency {
NotificationCenter.default.addObserver(
self,
selector: #selector(didChangeExternally),
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: NSUbiquitousKeyValueStore.default
)

return NSUbiquitousKeyValueStore.default
}
}

/**
Expand Down

0 comments on commit 8a018f1

Please sign in to comment.