Skip to content

About

Read-only native CloudKit client for Swoop's Apple release data (Xcode, SDKs, simulator runtimes, restore images), mapped onto SwoopKit models.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

SwoopCloudKit

SwiftPM Swift Versions Platforms License GitHub Workflow Status Documentation

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.

Table of Contents

Requirements

  • 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.Swoop container 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.

Installation

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")]
  )
]

Usage

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)

What it reads

  • RestoreImage, through CloudKitRestoreImageService (one page, for Bushel's catalog).
  • SDKVersion, XcodeVersion and SimulatorRuntime, through CloudKitReleaseCatalog: every page, mapped to SwoopKit's SDKVersionRecord, XcodeVersionRecord and SimulatorRuntimeRecord. Records that don't map are returned as skips instead of failing the fetch. The types grant READ only to _icloud, so accountStatus() must be .available.

A development-signed build reads the container's Development environment; a Developer ID or App Store build reads Production.

Release-data snapshot and cache file

These build everywhere: they're outside #if canImport(CloudKit).

  • ReleaseDataSnapshot (in SwoopKit since 1.0.0-beta.2; SwoopCloudKit re-exports SwoopKit, so import SwoopCloudKit still brings it in): SDKVersion, XcodeVersion and SimulatorRuntime records with the fetchedAt date of the fetch. JSON with ISO 8601 dates; a file without simulatorRuntimes decodes with none. init(json:) reads one, such as an app's bundled snapshot.
  • ReleaseDataCacheFile: a disk cache's contents, the snapshot plus formatVersion (currently 1). decode(_:) checks the version before decoding records and throws a typed ReleaseDataCacheError. Where the file lives is up to the app.
  • CloudKitReleaseCatalog.fetchSnapshot(now:) fetches SDKVersion, XcodeVersion and SimulatorRuntime into a snapshot. An environment without the SimulatorRuntime record type (CKError.unknownItem) gives a snapshot with no runtime records instead of failing.
  • JSONEncoder.encodeAsserting(_:), plus SwoopKit's JSONDecoder.iso8601, JSONDecoder.decodeValue(_:from:) (typed throws) and JSONEncoder.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.

Documentation

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).

Development

swift build
swift test
make lint      # swift-format, SwiftLint, build, headers, periphery (run `mise install` once)
make docs

Lint tools are pinned in mise.toml. See AGENTS.md for the package's rules.

Branches

  • main: releases. It depends on SwoopKit from: "1.0.0-beta.2".
  • simulator: Stewed's working branch. Between releases it can depend on SwoopKit's simulator branch instead.

License

SwoopCloudKit is available under the MIT license. See LICENSE.

About

Read-only native CloudKit client for Swoop's Apple release data (Xcode, SDKs, simulator runtimes, restore images), mapped onto SwoopKit models.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages