A wrapper around NSUbiquitousKeyValueStore providing shorthand for settings/reading/clearing stored values.
The synchronize function synchronizes the in-memory storage with their stored state (and possibly the cloud state). This function should be called once during app start up and when the app comes back into foreground.
An implementation of SimpleCloudStoreProvider that returns the SimpleCloudStore instance provided during
initialization.
Providing an instance via View extensions
extension View {
func simpleCloudStoreProvider(_ provider: SimpleCloudStoreProvider) -> some View
func simpleCloudStore(_ store: SimpleCloudStore) -> some View
}
Retrieving an instance in your Views
struct FooView : View {
@Environment(\.simpleCloudStoreProvider) private var simpleCloudStoreProvider
var body : some View {
Test("Bar")
.onAppear {
let value = simpleCloudStoreProvider.store
.getBool(forKey: "someKey")
print("Value: \(value))
}
}
}
SwiftSimpleCloudStore Library
An open source library that provides a wrapper around
NSUbiquitousKeyValueStoreto access cloud synched simple storage.Developed as re-usable components for various projects at XII’s iOS, macOS, and watchOS applications.
Installation
Swift Package Manager
SwiftSimpleCloudStorelibrary to add to your projectDependencies
License
See the LICENSE file.
SimpleCloudStoreservice (Source)A wrapper around
NSUbiquitousKeyValueStoreproviding shorthand for settings/reading/clearing stored values.The
synchronizefunction synchronizes the in-memory storage with their stored state (and possibly the cloud state). This function should be called once during app start up and when the app comes back into foreground.Adding the store to your environment (Source)
The
SimpleCloudServiceProviderprotocolDefines a provider that can return an instance of
SimpleCloudService.Indirect access to the store is used via this provider protocol to prevent multiple stores from being initialized in
EnvironmentValues.Two provider implementation available
An implementation of
SimpleCloudStoreProviderthat is used when noSimpleCloudStoreis available.Raises a
fatalErrorif the store is requested.An implementation of
SimpleCloudStoreProviderthat returns theSimpleCloudStoreinstance provided during initialization.Providing an instance via
ViewextensionsRetrieving an instance in your
Views