Skip to content

Commit

Permalink
Update SyncState docs and observer
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLeif committed Nov 29, 2023
1 parent e45eaf9 commit 15cde78
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/AppState/Application/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ open class Application: NSObject, ObservableObject {
self,
selector: #selector(didChangeExternally),
name: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: nil
object: NSUbiquitousKeyValueStore.default
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ extension Application {
dependency(NSUbiquitousKeyValueStore.default)
}

/// The `SyncState` struct is a data structure designed to handle the state synchronization of an application that supports the `Codable` type.
/// It utilizes Apple's iCloud Key-Value Store to propagate state changes across multiple devices.
/**
The `SyncState` struct is a data structure designed to handle the state synchronization of an application that supports the `Codable` type.
It utilizes Apple's iCloud Key-Value Store to propagate state changes across multiple devices.

- Note: The key-value store is intended for storing data that changes infrequently. As you test your devices, if the app on a device makes frequent changes to the key-value store, the system may defer the synchronization of some changes in order to minimize the number of round trips to the server. The more frequently the app make changes, the more likely the changes will be deferred and will not immediately show up on the other devices.
*/
public struct SyncState<Value: Codable>: CustomStringConvertible {
@AppDependency(\.icloudStore) private var icloudStore: NSUbiquitousKeyValueStore

Expand Down
6 changes: 5 additions & 1 deletion Sources/AppState/PropertyWrappers/SyncState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import Foundation
import Combine
import SwiftUI

/// `SyncState` is a property wrapper that allows SwiftUI views to subscribe to Application's state changes in a reactive way. The state is synchronized using `NSUbiquitousKeyValueStore`, and it works similarly to `State` and `Published`.
/**
`SyncState` is a property wrapper that allows SwiftUI views to subscribe to Application's state changes in a reactive way. The state is synchronized using `NSUbiquitousKeyValueStore`, and it works similarly to `State` and `Published`.

- Note: The key-value store is intended for storing data that changes infrequently. As you test your devices, if the app on a device makes frequent changes to the key-value store, the system may defer the synchronization of some changes in order to minimize the number of round trips to the server. The more frequently the app make changes, the more likely the changes will be deferred and will not immediately show up on the other devices.
*/
@propertyWrapper public struct SyncState<Value: Codable>: DynamicProperty {
/// Holds the singleton instance of `Application`.
@ObservedObject private var app: Application = Application.shared
Expand Down

0 comments on commit 15cde78

Please sign in to comment.