A read-only reader for the public CloudKit database of iCloud.com.brightdigit.Swoop, using native CloudKit.framework. It maps CKRecords onto the record models from SwoopKit. Bushel and Stewed share it.
SwoopMistKit writes the database. This package only queries it, and it needs no API token or server-to-server key: it uses the app's iCloud entitlement.
- Requirements
- Installation
- Usage
- What it reads
- Release-data snapshot and cache file
- Documentation
- Development
- Branches
- License
- Swift 6.4 (Xcode 27.2) or later.
- macOS 14, iOS 18, watchOS 11, tvOS 18, visionOS 2 or Mac Catalyst 18 or later for the CloudKit readers, with the iCloud (CloudKit) capability and the
iCloud.com.brightdigit.Swoopcontainer in the app's entitlements, and a signed-in iCloud account at run time. - The snapshot, cache file and JSON helpers also build on Linux.
dependencies: [
.package(url: "https://github.com/brightdigit/SwoopCloudKit.git", from: "1.0.0-alpha.1")
],
targets: [
.target(
name: "MyApp",
dependencies: [.product(name: "SwoopCloudKit", package: "SwoopCloudKit")]
)
]import SwoopCloudKit
let catalog = CloudKitReleaseCatalog()
guard try await catalog.accountStatus() == .available else {
// Ask the user to sign in to iCloud, or keep using cached data.
return
}
let snapshot = try await catalog.fetchSnapshot(now: .now)
try ReleaseDataCacheFile.encode(snapshot).write(to: cacheURL, options: .atomic)RestoreImage, throughCloudKitRestoreImageService(one page, for Bushel's catalog).SDKVersion,XcodeVersionandSimulatorRuntime, throughCloudKitReleaseCatalog: every page, mapped to SwoopKit'sSDKVersionRecord,XcodeVersionRecordandSimulatorRuntimeRecord. Records that don't map are returned as skips instead of failing the fetch. The types grantREADonly to_icloud, soaccountStatus()must be.available.
A development-signed build reads the container's Development environment; a Developer ID or App Store build reads Production.
These build everywhere: they're outside #if canImport(CloudKit).
ReleaseDataSnapshot(in SwoopKit since 1.0.0-beta.2; SwoopCloudKit re-exports SwoopKit, soimport SwoopCloudKitstill brings it in):SDKVersion,XcodeVersionandSimulatorRuntimerecords with thefetchedAtdate of the fetch. JSON with ISO 8601 dates; a file withoutsimulatorRuntimesdecodes with none.init(json:)reads one, such as an app's bundled snapshot.ReleaseDataCacheFile: a disk cache's contents, the snapshot plusformatVersion(currently 1).decode(_:)checks the version before decoding records and throws a typedReleaseDataCacheError. Where the file lives is up to the app.CloudKitReleaseCatalog.fetchSnapshot(now:)fetchesSDKVersion,XcodeVersionandSimulatorRuntimeinto a snapshot. An environment without theSimulatorRuntimerecord type (CKError.unknownItem) gives a snapshot with no runtime records instead of failing.JSONEncoder.encodeAsserting(_:), plus SwoopKit'sJSONDecoder.iso8601,JSONDecoder.decodeValue(_:from:)(typed throws) andJSONEncoder.iso8601PrettySorted: the coders the files use.
Moved from Stewed's StewedKit (Stewed #124); the snapshot and the three SwoopKit coders then moved down to SwoopKit so SwoopMistKit can write the same JSON (Stewed #194). The JSON is unchanged: Tests/SwoopCloudKitTests/Resources/release-data/cache-format-1.json was written by Stewed's code before the move, and the tests check that it decodes and re-encodes to the same bytes.
Tests (swift test) cover the CKRecord mappings with hand-built records, and the snapshot and cache file with the JSON fixtures in Tests/SwoopCloudKitTests/Resources/release-data/ (copies of Stewed's docs/fixtures/release-data/). They never open a CKContainer, which traps without the iCloud entitlement, so they need no iCloud account or network.
Seeded from Bushel's BushelCloudKitDebug module (v3.0.0-alpha.3, 46b6240): the RestoreImage query, the account-status check, the RestoreImageRecord mapping and the CKRecord value helpers. The SwiftUI debug window and the ImageMetadata derivation stayed in Bushel, because they depend on Bushel's app modules.
The DocC catalog is in Sources/SwoopCloudKit/SwoopCloudKit.docc, with articles on reading release data from CloudKit and on caching it. Build it with make docs (Scripts/docc.sh, warnings as errors; output in .build/docs) or preview it with make docs-preview. The package doesn't depend on swift-docc-plugin, so packages that depend on SwoopCloudKit never resolve it. Swift Package Index hosts the published documentation (.spi.yml).
swift build
swift test
make lint # swift-format, SwiftLint, build, headers, periphery (run `mise install` once)
make docsLint tools are pinned in mise.toml. See AGENTS.md for the package's rules.
main: releases. It depends on SwoopKitfrom: "1.0.0-beta.2".simulator: Stewed's working branch. Between releases it can depend on SwoopKit'ssimulatorbranch instead.
SwoopCloudKit is available under the MIT license. See LICENSE.