From 55c25e8153770262ace4a6a89007793c70ec053f Mon Sep 17 00:00:00 2001 From: Leif Date: Fri, 15 Dec 2023 14:55:11 -0700 Subject: [PATCH] Add more documentation to didChangeExternally --- Sources/AppState/Application/Application.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sources/AppState/Application/Application.swift b/Sources/AppState/Application/Application.swift index f3ba878..ebabf17 100644 --- a/Sources/AppState/Application/Application.swift +++ b/Sources/AppState/Application/Application.swift @@ -96,6 +96,21 @@ open class Application: NSObject, ObservableObject { consume(object: cache) } + /** + Called when the value of one or more keys in the local key-value store changed due to incoming data pushed from iCloud. + + This notification is sent only upon a change received from iCloud; it is not sent when your app sets a value. + + The user info dictionary can contain the reason for the notification as well as a list of which values changed, as follows: + - The value of the ``NSUbiquitousKeyValueStoreChangeReasonKey`` key, when present, indicates why the key-value store changed. Its value is one of the constants in Change Reason Values. + - The value of the ``NSUbiquitousKeyValueStoreChangedKeysKey``, when present, is an array of strings, each the name of a key whose value changed. + + The notification object is the ``NSUbiquitousKeyValueStore`` object whose contents changed. + + Changes you make to the key-value store are saved to memory. The system then synchronizes the in-memory keys and values with the local on-disk cache, automatically and at appropriate times. For example, it synchronizes the keys when your app is put into the background, when changes are received from iCloud, and when your app makes changes to a key but does not call the synchronize() method for several seconds. + + - Note: Calling `Application.dependency(\.icloudStore).synchronize()` does not force new keys and values to be written to iCloud. Rather, it lets iCloud know that new keys and values are available to be uploaded. Do not rely on your keys and values being available on other devices immediately. The system controls when those keys and values are uploaded. The frequency of upload requests for key-value storage is limited to several per minute. + */ @objc @available(iOS 15.0, watchOS 9.0, macOS 11.0, tvOS 15.0, *) open func didChangeExternally(notification: Notification) { Application.log(