Swiftpack.co - chris-araman/AsyncCloudKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by chris-araman.
chris-araman/AsyncCloudKit 1.0.1
🌤 Swift extensions for asynchronous CloudKit record processing
⭐️ 26
🕓 2 years ago
iOS macOS watchOS tvOS macCatalyst
.package(url: "https://github.com/chris-araman/AsyncCloudKit.git", from: "1.0.1")

⛅️ AsyncCloudKit

Swift extensions for asynchronous CloudKit record processing. Designed for simplicity.

Swift Platforms License Release

Lint | Build | Test Coverage

AsyncCloudKit exposes CloudKit operations as async functions and AsyncSequences.

⚠️ Deprecated

I am unfortunately unable to maintain this project moving forward. If you would like to fork and maintain it, please reach out.

Please consider making use of the new async functionality in CloudKit and SwiftData.

📦 Adding AsyncCloudKit to Your Project

AsyncCloudKit is a Swift Package. Add a dependency on AsyncCloudKit to your Package.swift using Xcode or the Swift Package Manager. Optionally, specify a version requirement.

dependencies: [
  .package(url: "https://github.com/chris-araman/AsyncCloudKit.git", from: "1.0.0")
]

Then resolve the dependency:

swift package resolve

To update to the latest AsyncCloudKit version compatible with your version requirement:

swift package update AsyncCloudKit

🌤 Using AsyncCloudKit in Your Project

Swift concurrency allows you to process CloudKit records asynchronously, without writing a lot of boilerplate code involving CKOperations and completion blocks. Here, we perform a query on our CKDatabase, then process the results asynchronously. As each CKRecord is read from the database, we print its name field.

import CloudKit
import AsyncCloudKit

func queryDueItems(database: CKDatabase, due: Date) async throws {
  for try await record in database
    .performQuery(ofType: "ToDoItem", where: NSPredicate(format: "due >= %@", due)) { (record: CKRecord) in
    print("\(record.name)")
  })
}

Cancellation

AsyncCloudKit functions that return an ACKSequence queue an operation immediately. Iterating the sequence allows you to inspect the results of the operation. If you stop iterating the sequence early, the operation may be cancelled.

Note that because the atBackgroundPriority functions are built on CKDatabase methods that do not provide means of cancellation, they cannot be canceled. If you need operations to respond to requests for cooperative cancellation, please use the publishers that do not have atBackgroundPriority in their names. You can still specify QualityOfService.background by passing in a CKOperation.Configuration.

📘 Documentation

💯% documented using Jazzy. Hosted by GitHub Pages.

❤️ Contributing

Contributions are welcome!

📚 Further Reading

To learn more about Swift Concurrency and CloudKit, watch these videos from WWDC:

...or review Apple's documentation:

If you're looking for Swift Combine extensions for CloudKit, take a look at CombineCloudKit!

📜 License

AsyncCloudKit was created by Chris Araman. It is published under the MIT license.

GitHub

link
Stars: 26
Last commit: 21 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.1: Remove Dependencies
2 years ago

📦 Removed a dependency on swift-format, as it's used only during development. Swift Package Manager doesn't yet provide a way to distinguish development dependencies.

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