Swiftpack.co - xiiagency/SwiftSimpleCloudStore as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by xiiagency.
xiiagency/SwiftSimpleCloudStore 1.0.0
An open source library that provides a wrapper around NSUbiquitousKeyValueStore to access cloud synched simple storage
⭐️ 0
🕓 1 week ago
iOS macOS watchOS
.package(url: "https://github.com/xiiagency/SwiftSimpleCloudStore.git", from: "1.0.0")

SwiftSimpleCloudStore Library


An open source library that provides a wrapper around NSUbiquitousKeyValueStore to access cloud synched simple storage.

Developed as re-usable components for various projects at XII's iOS, macOS, and watchOS applications.


Swift Package Manager

  1. In Xcode, select File > Swift Packages > Add Package Dependency.
  2. Follow the prompts using the URL for this repository
  3. Select the SwiftSimpleCloudStore library to add to your project



See the LICENSE file.

SimpleCloudStore service (Source)

class SimpleCloudStore {
  static let DEFAULT_LOG_LEVEL: OSLogType = .info

  init(logLevel: OSLogType = DEFAULT_LOG_LEVEL)

  func synchronize()

  func getArray<Element>(
    forKey: String,
    defaultValue: [Element]
  ) -> [Element]

  func getBool(forKey: String) -> Bool

  func getData(
    forKey: String,
    defaultValue: Data
  ) -> Data

  func getDictionary<Value>(
    forKey: String,
    defaultValue: [String: Value]
  ) -> [String: Value]

  func getDouble(forKey: String) -> Double

  func getInt(forKey: String) -> Int

  func getSet<Element>(
    forKey: String,
    defaultValue: Set<Element>
  ) -> Set<Element>

  func getString(
    forKey: String,
    defaultValue: String
  ) -> String

  func set<Element>(forKey: String, value: Array<Element>)

  func set(forKey: String, value: Bool)

  func set(forKey: String, value: Data)

  func set<Value>(forKey: String, value: [String: Value])

  func set(forKey: String, value: Double)

  func set(forKey: String, value: Int)

  func set<Element>(forKey: String, value: Set<Element>)

  func set(forKey: String, value: String)

  func clear(forKey: String)

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.

Adding the store to your environment (Source)

The SimpleCloudServiceProvider protocol

protocol SimpleCloudStoreProvider {
  var store: SimpleCloudStore { get }

Defines 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

struct UnavailableSimpleCloudStoreProvider : SimpleCloudStoreProvider { }

An implementation of SimpleCloudStoreProvider that is used when no SimpleCloudStore is available.

Raises a fatalError if the store is requested.

struct StaticSimpleCloudStoreProvider : SimpleCloudStoreProvider { }

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 {
      .onAppear {
        let value = simpleCloudStoreProvider.store
          .getBool(forKey: "someKey")

        print("Value: \(value))


Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1 week ago

Initial public release

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics