Skip to content

Latest commit

 

History

History
260 lines (249 loc) · 44.3 KB

CloudKit.md

File metadata and controls

260 lines (249 loc) · 44.3 KB

CloudKit

Symbols: 77.0% of Apple's iOS API (718 of 933, exact) · Rows: 11: 9 ✅ 2 ❌ · iOS: 8.0+

Area: Data & persistence · Apple: CloudKit · Issues: area:data

How isim implements it

  • Adapted: a local JSON store under $ISIM_DATA/Library/isim/CloudKit/<container>/, with a simulated account and in-process push payloads. There is no iCloud.
  • Objective-C / C interface: #import <CloudKit/CloudKit.h>, -framework CloudKit (#573).
    • The classes are the overlay's under Apple's names and selectors, with nested classes as Objective-C names them: CKRecordID, CKRecordZoneID, CKReference, CKQueryCursor, CKOperationConfiguration, CKFetchRecordZoneChangesConfiguration, CKShareParticipant, CKShareMetadata, CKUserIdentityLookupInfo, CKNotificationInfo.
    • Record values are Objective-C objects (objectForKey: and keyed subscripts).
    • The operations' blocks are Apple's (item, object, NSError) forms.
    • The enums and option sets are their C types.
    • CKOperation is an NSObject, not an NSOperation: add operations to a container or database (addOperation:).
    • CKSyncEngine itself is Swift-only; its enums have headers.

API

API / feature Status iOS Notes
CloudKit: containers, account (CKContainer.default(), accountStatus, userRecordID, ISIM_ICLOUD=noAccount) ✅ ≤17 local, no iCloud sync: a simulated account; ISIM_ICLOUD=noAccount|restricted|temporarilyUnavailable changes the status, and private/shared operations (and public writes) fail with CKError.notAuthenticated. Default container iCloud.<bundle id>. Tested: HelloCloudKit
CloudKit: records (CKRecord typed values, CKAsset, CKRecord.Reference, CLLocation, lists, changedKeys, change tags, dates, encodeSystemFields) ✅ ≤17 stored per container/database as JSON in $ISIM_DATA/Library/isim/CloudKit/<container>/; assets copied into the store; .deleteSelf references cascade; values read back as Objective-C-style values (as? String/Int/Double/Date/[String]). encryptedValues are stored like other fields (not encrypted at rest). Tested: HelloCloudKit (relaunch persistence)
CloudKit: CKDatabase save/fetch/delete (+ async), records(matching:), modifyRecords, CKQuery (NSPredicate + sort), CKQueryOperation (cursor, resultsLimit), CKModifyRecordsOperation (save policies, atomic), CKFetchRecordsOperation, CKError ✅ ≤17 serverRecordChanged with server/client records, .changedKeys/.allKeys, atomic batches in custom zones (batchRequestFailed), unknownItem for missing records/types, partialFailure. Predicates use isim's NSPredicate (no distanceToLocation:); CKOperation is not an NSOperation (isim has none): add operations to a database/container. Tested: HelloCloudKit
CloudKit: zones, change tokens (CKRecordZone, CKFetchDatabaseChangesOperation, CKFetchRecordZoneChangesOperation) ✅ ≤17 custom zones in the private database, zone changes/deletions since a persistent CKServerChangeToken, resultsLimit paging and moreComing. Tested: HelloCloudKit (database + zone changes)
CloudKit: subscriptions (CKQuerySubscription, CKDatabaseSubscription, CKRecordZoneSubscription, CKNotification) ✅ ≤17 saved, fetched and deleted persistently; matching changes made in this process send a CloudKit-style push payload in-process to application(_:didReceiveRemoteNotification:fetchCompletionHandler:). Adapted: no APNs, cross-process delivery or alert banner. Tested: HelloCloudKit (query + database)
CloudKit: sharing (CKShare with url, CKShare.SystemFieldKey, CKShare.Metadata, CKFetchShareMetadataOperation, CKAcceptSharesOperation, CKContainer.shareMetadata(for:) / shareMetadatas(for:) / fetchShareMetadata(with:) / accept(_:), CKAllowedSharingOptions with CKSharingParticipantPermissionOption / CKSharingParticipantAccessOption, CKSystemSharingUIObserver, UICloudSharingController), user discovery ✅ ≤17 adapted locally: shares keep their owner, public permission and participants in the store; a saved share's url names its container, zone and record, so any app on the device reads its metadata (the current user's role, permission and status, the owner, the root record on request) and accepts it as the device's simulated Apple Account (AppleAccount/account.json): an invited participant becomes accepted, anyone else joins as a public user when the share has a public permission, and the owner accepting is a no-op. Participants found by email get the record name that account has when signed in. Shared records stay in the owner's database (isim's databases are per container, not per account), and no invitation is sent. UICloudSharingController is iOS's sheet (adapted): the item's thumbnail and title, People (each participant's status and permission), Share Options (who can access and their permission, as availablePermissions allows), Copy Link and Stop Sharing, in the emulated iOS version's bars; CKSystemSharingUIObserver hears it save a share (Done saves the options changed in it) or stop sharing (which deletes the share). CKAllowedSharingOptions are kept. Tested: HelloCloudKit (tests/ui/test_cloudkit.py: the owner, an invited participant and a public user open the link; the sheet shows the share, changes the link's permission, saves and stops sharing). Opened share links reach the app of the container through UIKit (UIKit, #575), in Swift through the delegate methods too. CKShare.Metadata is the top-level CKShareMetadata of the _CKShareMetadata module, where Swift resolves UIKit's declarations (#630; its Swift ABI changed in 0.28). CKShare.SystemFieldKey's title, thumbnailImageData and shareType are CKRecord.FieldKey constants, as on iOS (share[CKShare.SystemFieldKey.title]). Tested (CloudKitShareSwiftTest: the title, the metadata archived and decoded)
CloudKit: CKFetchRecordZonesOperation, CKFetchSubscriptionsOperation (and their fetchAll… forms), CKOperation.group ✅ ≤17 adapted: run against the local store, with per-item and final result blocks; an operation's group (CKOperationGroup) is kept. Tested: HelloCloudKit
CloudKit: CKSyncEngine (Configuration, State with Serialization, PendingRecordZoneChange, PendingDatabaseChange, RecordZoneChangeBatch, FetchChangesOptions / SendChangesOptions and their scopes, FetchChangesContext / SendChangesContext, SyncReason, Event and its twelve kinds, CKSyncEngineDelegate with nextFetchChangesOptions), CKDatabase.RecordZoneChange, CKDatabase.DatabaseChange, CKOperationGroup, the CKSyncEngine… enums ✅ 17.0 adapted: the "server" is the device's local CloudKit database, so engines (and apps) on the device that use the container sync with each other and nothing reaches iCloud. Fetches report zone changes, then each zone's record changes since the engine's per-zone tokens (prioritized zones first; an engine's own writes are not handed back); sends save and delete pending zones first, then ask the delegate for batches until it has none, reporting failures as CKErrors (serverRecordChanged for stale records); accountChange reports the simulated account signing in, out or switching. With automaticallySync, the engine fetches when it starts and sends 0.2 s after pending changes are added (nextFetchChangesOptions is asked for those). Tokens and pending changes are in the opaque serialization. cancelOperations() cancels scheduled syncs. The CKSyncEngine… enums are Swift @objc enums with proposed raw values (their Objective-C headers: CloudKit/CKSyncEngine.h). Tested: HelloCloudKit (tests/ui/test_cloudkit.py: two engines, a stale save, a restored engine syncing a new zone automatically)
Objective-C: CKContainer (+defaultContainer, +containerWithIdentifier:, addOperation:, databaseWithDatabaseScope:, accountStatusWithCompletionHandler:, share metadata and participants), CKDatabase's convenience methods (saveRecord:, fetchRecordWithID:, deleteRecordWithID:, performQuery:inZoneWithID:, zones, subscriptions), CKRecord (keyed subscripts, objectForKey:, encryptedValues, encodeSystemFieldsWithCoder:, setParentReferenceFromRecord(ID):), CKRecordID, CKRecordZone(ID), CKReference, CKAsset, CKQuery, the operations with Apple's blocks (recordMatchedBlock, perRecordSaveBlock / perRecordDeleteBlock, perRecordZoneCompletionBlock / fetchRecordZonesCompletionBlock, recordWasChangedBlock / recordZoneFetchCompletionBlock, …), subscriptions and +notificationFromRemoteNotificationDictionary:, CKShare (URL), CKShareMetadata, CKAllowedSharingOptions, CKErrorDomain / CKErrorCode and its keys, the CKSyncEngine… enums ✅ ≤17 adapted: the overlay's classes (above); per-item blocks are kept per operation and called from the Swift result blocks. Tested (CloudKitObjCTest, test_cloudkit_objc: typed values, a conflict and partial failures, a paged query, zone and database changes with an archived token, subscriptions with an in-process push to the Objective-C app delegate, a share and its metadata)
Types not yet in isim (iOS 17 and earlier) ❌ ≤17 not implemented, found by the 2026-10 sweep: CKAllowedSharingOptions, CKFetchRecordZonesOperation, CKFetchShareMetadataOperation, CKFetchShareParticipantsOperation, CKFetchSubscriptionsOperation, CKFetchWebAuthTokenOperation, CKLocationSortDescriptor, CKOperationGroup, CKShareTransferRepresentation, CKSystemSharingUIObserver (10 types; with their members under "Not yet in isim")
Types not yet in isim (iOS 26) ❌ 26.0 not implemented, found by the 2026-10 sweep: CKShareRequestAccessOperation (1 type; with its members under "Not yet in isim")

Not yet in isim

215 symbols Apple documents for iOS that isim does not have (exact; Apple snapshot 2026-10-14). Each links to Apple's documentation.

List