One Logo Pool Ball
CloudKit · IOS API REFERENCE

CKDatabase

class · iOS 8.0+ · SDK 27.1

class CKDatabase

Members (49)

method · iOS 8.0+

add

TypeScript
add(operation: CKDatabaseOperation): void
Swift declaration
func add(_ operation: CKDatabaseOperation)
method

delete

TypeScript
deleteWithRecordIDCompletionHandler(recordID: CKRecord_ID, completionHandler: ((arg0: (CKRecord_ID) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func delete(withRecordID recordID: CKRecord.ID) async throws -> CKRecord.ID
method

delete

TypeScript
deleteWithRecordZoneIDCompletionHandler(zoneID: CKRecordZone_ID, completionHandler: ((arg0: (CKRecordZone_ID) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func delete(withRecordZoneID zoneID: CKRecordZone.ID) async throws -> CKRecordZone.ID
method

fetchAllRecordZones

TypeScript
fetchAllRecordZones(completionHandler: ((arg0: (Array<CKRecordZone>) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func fetchAllRecordZones(completionHandler: @escaping @Sendable ([CKRecordZone]?, (any Error)?) -> Void)
method · iOS 8.0+

fetchAllSubscriptions

TypeScript
fetchAllSubscriptions(completionHandler: ((arg0: (Array<CKSubscription>) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func fetchAllSubscriptions(completionHandler: @escaping @Sendable ([CKSubscription]?, (any Error)?) -> Void)
method

fetch

TypeScript
fetchWithRecordIDCompletionHandler(recordID: CKRecord_ID, completionHandler: ((arg0: (CKRecord) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func fetch(withRecordID recordID: CKRecord.ID) async throws -> CKRecord
method

fetch

TypeScript
fetchWithRecordZoneIDCompletionHandler(zoneID: CKRecordZone_ID, completionHandler: ((arg0: (CKRecordZone) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func fetch(withRecordZoneID zoneID: CKRecordZone.ID) async throws -> CKRecordZone
method · iOS 8.0+ · Deprecated in iOS 15.0

perform

TypeScript
performInZoneWithCompletionHandler(query: CKQuery, zoneID: (CKRecordZone_ID) | null, completionHandler: ((arg0: (Array<CKRecord>) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func perform(_ query: CKQuery, inZoneWith zoneID: CKRecordZone.ID?, completionHandler: @escaping @Sendable ([CKRecord]?, (any Error)?) -> Void)
method

save

TypeScript
saveCompletionHandler(record: CKRecord, completionHandler: ((arg0: (CKRecord) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func save(_ record: CKRecord, completionHandler: @escaping @Sendable (CKRecord?, (any Error)?) -> Void)
method

save

TypeScript
saveCompletionHandler10675(zone: CKRecordZone, completionHandler: ((arg0: (CKRecordZone) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func save(_ zone: CKRecordZone, completionHandler: @escaping @Sendable (CKRecordZone?, (any Error)?) -> Void)
method · iOS 8.0+

save

TypeScript
saveCompletionHandler5505(subscription: CKSubscription, completionHandler: ((arg0: (CKSubscription) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
func save(_ subscription: CKSubscription, completionHandler: @escaping @Sendable (CKSubscription?, (any Error)?) -> Void)
get · iOS 10.0+

databaseScope

TypeScript
get databaseScope(): CKDatabase_Scope
Swift declaration
var databaseScope: CKDatabase.Scope { get }
method · iOS 15.0+

recordZone

TypeScript
recordZone(zoneID: CKRecordZone_ID): Promise<CKRecordZone>
Swift declaration
func recordZone(for zoneID: CKRecordZone.ID) async throws -> CKRecordZone

Fetches a specific record zone. - Parameters: - zoneID: The identifier of the record zone to fetch. - Returns: The fetched record zone. This method throws an error if the request fails, such as when the zone does not exist, the network is unavailable or the device doesn't have an active iCloud account. For information on a more convenient way to fetch specific record zones, see ``CKDatabase/recordZones(for:)``.

method · iOS 15.0+

recordZones

TypeScript
recordZones(ids: Array<CKRecordZone_ID>): Promise<NativeMap<CKRecordZone_ID, SDKHandle>>
Swift declaration
func recordZones(for ids: [CKRecordZone.ID]) async throws -> [CKRecordZone.ID : Result<CKRecordZone, any Error>]

Fetches the specified record zones and returns them to an awaiting caller. - Parameters: - ids: The identifiers of the record zones to fetch. - Returns: A dictionary that contains the fetched record zones. The dictionary uses the specified record zone identifiers as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding fetched record zone, or an error that describes why CloudKit can't provide that record zone. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account; otherwise, the returned dictionary includes any individual record zone errors. For information on a more configurable way to fetch specific record zones, see ``CKFetchRecordZonesOperation``.

method · iOS 15.0+

deleteRecord

TypeScript
deleteRecord(recordID: CKRecord_ID): Promise<CKRecord_ID>
Swift declaration
@discardableResult func deleteRecord(withID recordID: CKRecord.ID) async throws -> CKRecord.ID

Deletes a specific record. - Parameters: - recordID: The identifier of the record to delete. - Returns: The identifier of the deleted record. Deleting a record may cause additional deletions if other records in the database reference the deleted record. CloudKit doesn't provide the identifiers of any additional records it deletes. This method throws an error if the request fails, such as when the record doesn't exist, the network is unavailable or the device doesn't have an active iCloud account. For information on a more convenient way to delete records, see ``CKDatabase/modifyRecords(saving:deleting:savePolicy:atomically:)``.

method · iOS 15.0+

subscription

TypeScript
subscription(subscriptionID: string): Promise<CKSubscription>
Swift declaration
func subscription(for subscriptionID: CKSubscription.ID) async throws -> CKSubscription

Fetches a specific subscription and returns it to an awaiting caller. - Parameters: - subscriptionID: The identifier of the subscription to fetch. - Returns: The fetched subscription. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account.

method · iOS 15.0+

modifyRecords

TypeScript
modifyRecordsSavingDeletingSavePolicyAtomicallyCompletionHandler(recordsToSave: Array<CKRecord>, recordIDsToDelete: Array<CKRecord_ID>, savePolicy: CKModifyRecordsOperation_RecordSavePolicy, atomically: boolean, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func modifyRecords(saving recordsToSave: [CKRecord], deleting recordIDsToDelete: [CKRecord.ID], savePolicy: CKModifyRecordsOperation.RecordSavePolicy = .ifServerRecordUnchanged, atomically: Bool = true, completionHandler: @escaping @Sendable (Result<(saveResults: [CKRecord.ID : Result<CKRecord, any Error>], deleteResults: [CKRecord.ID : Result<Void, any Error>]), any Error>) -> Void)

Modifies the specified records and delivers the results to a completion handler. - Parameters: - recordsToSave: The records to save. - recordIDsToDelete: The identifiers of the records to permanently delete. - savePolicy: The policy to use when modifying existing records. For possible values, see ``CKModifyRecordsOperation/RecordSavePolicy``. - atomically: If <doc://com.apple.documentation/documentation/swift/true>, the entire operation fails if CloudKit can't modify one or more of the specified records; otherwise, CloudKit reports individual failures in the returned tuple. Atomic changes are only applicable in record zones that have the ``CKRecordZone/Capabilities/atomic`` capability. - completionHandler: The closure to execute after CloudKit processes the changes. The completion handler takes a single <doc://com.apple.documentation/documentation/swift/result> parameter that contains either a tuple, or an error if the request fails. For example, when the network is unavailable or the device doesn't have an active iCloud account, or when `atomically` is <doc://com.apple.documentation/documentation/swift/true> and one or more of the specified changes fail. When present, the tuple contains the following named elements: - term `saveResults`: A dictionary of saved records. The dictionary uses the identifiers of the records you specify in `recordsToSave` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding modified record (as it appears on the server), or an error that describes why CloudKit can't modify that record. - term `deleteResults`: A dictionary of deleted records. The dictionary uses the identifiers you specify in `recordIDsToDelete` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either <doc://com.apple.documentation/documentation/swift/void> to indicate a successful deletion, or an error that describes why CloudKit can't delete that record. Deleting records may cause additional deletions if other records in the database reference the deleted records. CloudKit doesn't provide the identifiers of any additional records it deletes. For information on a more configurable way to modify records, see ``CKModifyRecordsOperation``.

method · iOS 15.0+

modifyRecords

TypeScript
modifyRecordsSavingDeletingSavePolicyAtomically(recordsToSave: Array<CKRecord>, recordIDsToDelete: Array<CKRecord_ID>, savePolicy?: CKModifyRecordsOperation_RecordSavePolicy, atomically?: boolean): Promise<{ "saveResults": NativeMap<CKRecord_ID, SDKHandle>; "deleteResults": NativeMap<CKRecord_ID, SDKHandle> }>
Swift declaration
func modifyRecords(saving recordsToSave: [CKRecord], deleting recordIDsToDelete: [CKRecord.ID], savePolicy: CKModifyRecordsOperation.RecordSavePolicy = .ifServerRecordUnchanged, atomically: Bool = true) async throws -> (saveResults: [CKRecord.ID : Result<CKRecord, any Error>], deleteResults: [CKRecord.ID : Result<Void, any Error>])

Modifies the specified records and returns the results to an awaiting caller. - Parameters: - recordsToSave: The records to save. - recordIDsToDelete: The identifiers of the records to permanently delete. - savePolicy: The policy to use when modifying existing records. For possible values, see ``CKModifyRecordsOperation/RecordSavePolicy``. - atomically: If <doc://com.apple.documentation/documentation/swift/true>, the entire operation fails if CloudKit can't modify one or more of the specified records; otherwise, CloudKit reports individual failures in the returned tuple. Atomic changes are only applicable in record zones that have the ``CKRecordZone/Capabilities/atomic`` capability. - Returns: A tuple with the following named elements: - term `saveResults`: A dictionary of saved records. The dictionary uses the identifiers of the records you specify in `recordsToSave` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding modified record (as it appears on the server), or an error that describes why CloudKit can't modify that record. - term `deleteResults`: A dictionary of deleted records. The dictionary uses the identifiers you specify in `recordIDsToDelete` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either <doc://com.apple.documentation/documentation/swift/void> to indicate a successful deletion, or an error that describes why CloudKit can't delete that record. Deleting records may cause additional deletions if other records in the database reference the deleted records. CloudKit doesn't provide the identifiers of any additional records it deletes. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account, or when `atomically` is <doc://com.apple.documentation/documentation/swift/true> and one or more of the specified changes fail; otherwise, the returned tuple includes any individual record errors. For information on a more configurable way to modify records, see ``CKModifyRecordsOperation``.

method · iOS 15.0+

subscriptions

TypeScript
subscriptions(ids: Array<string>): Promise<Record<string, SDKHandle>>
Swift declaration
func subscriptions(for ids: [CKSubscription.ID]) async throws -> [CKSubscription.ID : Result<CKSubscription, any Error>]

Fetches the specified subscriptions and returns them to an awaiting caller. - Parameters: - ids: The identifiers of the subscriptions to fetch. - Returns: A dictionary that contains the fetched subscriptions. The dictionary uses the identifiers you specify in `ids` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding fetched subscription, or an error that describes why CloudKit can't provide that subscription. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account; otherwise, the returned dictionary includes any individual subscription errors. For information on a more configurable way to fetch specific subscriptions, see ``CKFetchSubscriptionsOperation``.

method · iOS 15.0+

allRecordZones

TypeScript
allRecordZones(): Promise<Array<CKRecordZone>>
Swift declaration
func allRecordZones() async throws -> [CKRecordZone]

Fetches all record zones from the current database. - Returns: An array of fetched record zones which contains at least one record zone, the default zone. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account.

method · iOS 15.0+

configuredWith

TypeScript
configuredWithConfigurationGroupBody(configuration: (CKOperation_Configuration) | null, group: (CKOperationGroup) | null, body: ((arg0: CKDatabase) => unknown)): unknown
Swift declaration
@discardableResult func configuredWith<R>(configuration: CKOperation.Configuration? = nil, group: CKOperationGroup? = nil, body: (CKDatabase) throws -> R) rethrows -> R

Applies a temporary configuration to the database within the scope of a closure. - Parameters: - configuration: An interim configuration to apply to the current database. - group: The group to associate with the methods you execute in the closure. Specifying a group helps the system prioritize those method calls, and helps you identify the calls in the server logs in CloudKit Console. For more information, see ``CKOperationGroup``. - body: The closure to execute with the temporarily configured database. Use this method to apply a specific configuration to the current database that lasts only for the duration of the trailing closure. For example, you might want to temporarily elevate the quality of service (QoS) for a group of method calls, or allow one or more expensive method calls to execute only while the device is using WiFi. ```swift func fetchRecords( with ids: [CKRecord.ID], completionHandler: @escaping ( Result<[CKRecord.ID : Result<CKRecord, any Error>], any Error> ) -> Void ) -> Void { // Get a reference to the user's private database. let database = CKContainer.default().privateCloudDatabase // Create a configuration that denies cellular access. let config = CKOperation.Configuration() config.allowsCellularAccess = false // Configure the database and execute an expensive fetch. database.configuredWith(configuration: config) { db in db.fetch(withRecordIDs: ids, completionHandler: completionHandler) } } ```

method · iOS 15.0+

configuredWith

TypeScript
configuredWithConfigurationGroupBody35481(configuration: (CKOperation_Configuration) | null, group: (CKOperationGroup) | null, body: ((arg0: CKDatabase) => Promise<unknown>)): Promise<unknown>
Swift declaration
@discardableResult @preconcurrency func configuredWith<R>(configuration: CKOperation.Configuration? = nil, group: CKOperationGroup? = nil, body: @Sendable (CKDatabase) async throws -> R) async rethrows -> R

Applies a temporary configuration to the database within the scope of a closure that supports concurrency. - Parameters: - configuration: An interim configuration to apply to the current database. - group: The group to associate with the methods you execute in the closure. Specifying a group helps the system prioritize those method calls, and helps you identify the calls in the server logs in CloudKit Console. For more information, see ``CKOperationGroup``. - body: The closure to execute with the temporarily configured database. Use this method to apply a specific configuration to the current database that lasts only for the duration of the trailing closure. For example, you might want to temporarily elevate the quality of service (QoS) for a group of method calls, or allow one or more expensive method calls to execute only while the device is using WiFi. ```swift func fetchRecords( with ids: [CKRecord.ID] ) async throws -> [CKRecord.ID: Result<CKRecord, any Error>] { // Get a reference to the user's private database. let database = CKContainer.default().privateCloudDatabase // Create a configuration that denies cellular access. let config = CKOperation.Configuration() config.allowsCellularAccess = false // Configure the database and execute an expensive fetch. return try await database.configuredWith(configuration: config) { db in try await db.records(for: ids) } } ```

method · iOS 15.0+

databaseChanges

TypeScript
databaseChanges(changeToken?: (CKServerChangeToken) | null, resultsLimit?: (number) | null): Promise<{ "modifications": Array<CKDatabase_DatabaseChange_Modification>; "deletions": Array<CKDatabase_DatabaseChange_Deletion>; "changeToken": CKServerChangeToken; "moreComing": boolean }>
Swift declaration
func databaseChanges(since changeToken: CKServerChangeToken?, resultsLimit: Int? = nil) async throws -> (modifications: [CKDatabase.DatabaseChange.Modification], deletions: [CKDatabase.DatabaseChange.Deletion], changeToken: CKServerChangeToken, moreComing: Bool)

Fetches all modified record zones and returns them to an awaiting caller. - Parameters: - changeToken: The change token from the previous execution of this method. If this is your app's first fetch, or you want to refetch every change in the database's history, specify `nil`. - resultsLimit: The maximum number of changes to return. The server may use a limit lower than this value. - Returns: A tuple with the following named elements: - term `modifications`: An array of database modifications that occur after the time that `changeToken` denotes. Each modification contains details about a modified record zone. - term `deletions`: An array of database deletions that occur after the time that `changeToken` denotes. Each deletion contains details about a deleted or purged record zone. - term `changeToken`: The change token that corresponds to the fetch results' most recent change. - term `moreComing`: A Boolean value that indicates whether the server has additional changes for you to fetch. This method fetches record zone changes in a database, which includes new record zones, changed zones — including deleted or purged zones — and zones that contain record changes. It throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account. Along with the fetched changes, CloudKit supplies a _change token_, which is an opaque token that denotes a specific point in the database's history. Store this token and provide it the next time you execute this method. Change tokens conform to <doc://com.apple.documentation/documentation/foundation/nssecurecoding> and are safe to cache on-disk. Don't infer any behavior or order from a token's contents. For information on a more configurable way to fetch database changes, see ``CKFetchDatabaseChangesOperation``.

method · iOS 15.0+

allSubscriptions

TypeScript
allSubscriptions(): Promise<Array<CKSubscription>>
Swift declaration
func allSubscriptions() async throws -> [CKSubscription]

Fetches all subscriptions from the current database. - Returns: The database's subscriptions. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account. For information on a more configurable way to fetch all subscriptions from a specific database, see ``CKFetchSubscriptionsOperation/fetchAllSubscriptionsOperation()``.

method · iOS 15.0+

deleteRecordZone

TypeScript
deleteRecordZone(zoneID: CKRecordZone_ID): Promise<CKRecordZone_ID>
Swift declaration
@discardableResult func deleteRecordZone(withID zoneID: CKRecordZone.ID) async throws -> CKRecordZone.ID

Deletes a specific record zone. - Parameters: - zoneID: The identifier of the record zone to delete. - Returns: The identifier of the deleted record zone. - Warning: Deleting a record zone is a permanent action that deletes every record in that zone. You can't restore a deleted record zone. This method throws an error if the request fails, such as when the zone does not exist on the server, the network is unavailable or the device doesn't have an active iCloud account. For information on a more convenient way to delete record zones, see ``CKDatabase/modifyRecordZones(saving:deleting:)``.

method · iOS 15.0+

modifyRecordZones

TypeScript
modifyRecordZonesSavingDeletingCompletionHandler(recordZonesToSave: Array<CKRecordZone>, recordZoneIDsToDelete: Array<CKRecordZone_ID>, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func modifyRecordZones(saving recordZonesToSave: [CKRecordZone], deleting recordZoneIDsToDelete: [CKRecordZone.ID], completionHandler: @escaping @Sendable (Result<(saveResults: [CKRecordZone.ID : Result<CKRecordZone, any Error>], deleteResults: [CKRecordZone.ID : Result<Void, any Error>]), any Error>) -> Void)

Modifies the specified record zones and delivers the results to a completion handler. - Parameters: - recordZonesToSave: The record zones to save. - recordZoneIDsToDelete: The identifiers of the record zones to permanently delete. - completionHandler: The closure to execute after CloudKit processes the changes. - Warning: Deleting a record zone is a permanent action that deletes every record in that zone. You can't restore a deleted record zone. The completion handler takes a single <doc://com.apple.documentation/documentation/swift/result> parameter that contains either a tuple, or an error if the request fails. For example, when the network is unavailable or the device doesn't have an active iCloud account. When present, the tuple contains the following named elements: - term `saveResults`: A dictionary of saved record zones. The dictionary uses the identifiers of the record zones you specify in `recordsZonesToSave` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding modified record zone (as it appears on the server), or an error that describes why CloudKit can't modify that record. - term `deleteResults`: A dictionary of deleted record zones. The dictionary uses the identifiers you specify in `recordZoneIDsToDelete` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either <doc://com.apple.documentation/documentation/swift/void> to indicate a successful deletion, or an error that describes why CloudKit can't delete that record zone. For information on a more configurable way to modify record zones, see ``CKModifyRecordZonesOperation``.

method · iOS 15.0+

modifyRecordZones

TypeScript
modifyRecordZonesSavingDeleting(recordZonesToSave: Array<CKRecordZone>, recordZoneIDsToDelete: Array<CKRecordZone_ID>): Promise<{ "saveResults": NativeMap<CKRecordZone_ID, SDKHandle>; "deleteResults": NativeMap<CKRecordZone_ID, SDKHandle> }>
Swift declaration
func modifyRecordZones(saving recordZonesToSave: [CKRecordZone], deleting recordZoneIDsToDelete: [CKRecordZone.ID]) async throws -> (saveResults: [CKRecordZone.ID : Result<CKRecordZone, any Error>], deleteResults: [CKRecordZone.ID : Result<Void, any Error>])

Modifies the specified record zones and returns the results to an awaiting caller. - Parameters: - recordZonesToSave: The record zones to save. - recordZoneIDsToDelete: The identifiers of the record zones to permanently delete. - Returns: A tuple with the following named elements: - term `saveResults`: A dictionary of saved record zones. The dictionary uses the identifiers of the record zones you specify in `recordZonesToSave` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding modified record zone (as it appears on the server), or an error that describes why CloudKit can't modify that record zone. - term `deleteResults`: A dictionary of deleted record zones. The dictionary uses the identifiers you specify in `recordZoneIDsToDelete` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either <doc://com.apple.documentation/documentation/swift/void> to indicate a successful deletion, or an error that describes why CloudKit can't delete that record zone. - Warning: Deleting a record zone is a permanent action that deletes every record in that zone. You can't restore a deleted record zone. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account; otherwise, the returned tuple includes any individual record zone errors. For information on a more configurable way to modify record zones, see ``CKModifyRecordZonesOperation``.

method · iOS 15.0+

recordZoneChanges

TypeScript
recordZoneChanges(zoneID: CKRecordZone_ID, changeToken?: (CKServerChangeToken) | null, desiredKeys?: (Array<string>) | null, resultsLimit?: (number) | null): Promise<{ "modificationResultsByID": NativeMap<CKRecord_ID, SDKHandle>; "deletions": Array<CKDatabase_RecordZoneChange_Deletion>; "changeToken": CKServerChangeToken; "moreComing": boolean }>
Swift declaration
func recordZoneChanges(inZoneWith zoneID: CKRecordZone.ID, since changeToken: CKServerChangeToken?, desiredKeys: [CKRecord.FieldKey]? = nil, resultsLimit: Int? = nil) async throws -> (modificationResultsByID: [CKRecord.ID : Result<CKDatabase.RecordZoneChange.Modification, any Error>], deletions: [CKDatabase.RecordZoneChange.Deletion], changeToken: CKServerChangeToken, moreComing: Bool)

Fetches all modified records from a specific record zone and returns them to an awaiting caller. - Parameters: - zoneID: The identifier of the record zone with changes. - changeToken: The change token from the previous execution of this method. If this is your app's first fetch, or you want to refetch every change in the record zone's history, specify `nil`. - desiredKeys: The fields to include on each fetched record. To include all fields, specify `nil`; to fetch only system fields, specify an empty array. - resultsLimit: The maximum number of changes to return. The server may use a limit lower than this value. - Returns: A tuple with the following named elements: - term `modificationResultsByID`: A dictionary of record modifications that occur after the time that `changeToken` denotes. The dictionary uses the identifiers of modified records as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding modification, or an error that describes why CloudKit can't provide that information. - term `deletions`: An array of record deletions that occur after the time that `changeToken` denotes. Each deletion contains details about a deleted record. - term `changeToken`: The change token that corresponds to the fetch results' most recent change. - term `moreComing`: A Boolean value that indicates whether the server has additional changes for you to fetch. This method fetches record changes in the specified record zone, such as those that occur during record creation, modification, and deletion. It throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account; otherwise, the returned tuple includes any individual record errors. Along with the fetched changes, CloudKit supplies a _change token_, which is an opaque token that denotes a specific point in the record zone's history. Store this token and provide it the next time you execute this method. Change tokens conform to <doc://com.apple.documentation/documentation/foundation/nssecurecoding> and are safe to cache on-disk. Don't infer any behavior or order from a token's contents. For information on a more configurable way to fetch record zone changes, see ``CKFetchRecordZoneChangesOperation``.

method · iOS 15.0+

deleteSubscription

TypeScript
deleteSubscription(subscriptionID: string): Promise<string>
Swift declaration
@discardableResult func deleteSubscription(withID subscriptionID: CKSubscription.ID) async throws -> CKSubscription.ID

Deletes a specific subscription and returns the deleted subscription's identifier to an awaiting caller. - Parameters: - subscriptionID: The identifier of the subscription to delete. - Returns: The identifier of the deleted subscription. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account. For information on a more convenient way to delete subscriptions, see ``CKDatabase/modifySubscriptions(saving:deleting:)``.

method · iOS 15.0+

modifySubscriptions

TypeScript
modifySubscriptionsSavingDeletingCompletionHandler(subscriptionsToSave: Array<CKSubscription>, subscriptionIDsToDelete: Array<string>, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func modifySubscriptions(saving subscriptionsToSave: [CKSubscription], deleting subscriptionIDsToDelete: [CKSubscription.ID], completionHandler: @escaping @Sendable (Result<(saveResults: [CKSubscription.ID : Result<CKSubscription, any Error>], deleteResults: [CKSubscription.ID : Result<Void, any Error>]), any Error>) -> Void)

Modifies the specified subscriptions and delivers the results to a completion handler. - Parameters: - subscriptionsToSave: The subscriptions to save. - subscriptionIDsToDelete: The identifiers of the subscriptions to permanently delete. - completionHandler: The closure to execute after CloudKit processes the changes. The completion handler takes a single <doc://com.apple.documentation/documentation/swift/result> parameter that contains either a tuple, or an error if the request fails. For example, when the network is unavailable or the device doesn't have an active iCloud account. When present, the tuple contains the following named elements: - term `saveResults`: A dictionary of saved subscriptions. The dictionary uses the identifiers of the subscriptions you specify in `subscriptionsToSave` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding modified subscription (as it appears on the server), or an error that describes why CloudKit can't modify that subscription. - term `deleteResults`: A dictionary of deleted subscriptions. The dictionary uses the identifiers you specify in `subscriptionIDsToDelete` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either <doc://com.apple.documentation/documentation/swift/void> to indicate a successful deletion, or an error that describes why CloudKit can't delete that subscription. For information on a more configurable way to modify subscriptions, see ``CKModifySubscriptionsOperation``.

method · iOS 15.0+

modifySubscriptions

TypeScript
modifySubscriptionsSavingDeleting(subscriptionsToSave: Array<CKSubscription>, subscriptionIDsToDelete: Array<string>): Promise<{ "saveResults": Record<string, SDKHandle>; "deleteResults": Record<string, SDKHandle> }>
Swift declaration
func modifySubscriptions(saving subscriptionsToSave: [CKSubscription], deleting subscriptionIDsToDelete: [CKSubscription.ID]) async throws -> (saveResults: [CKSubscription.ID : Result<CKSubscription, any Error>], deleteResults: [CKSubscription.ID : Result<Void, any Error>])

Modifies the specified subscriptions and returns the results to an awaiting caller. - Parameters: - subscriptionsToSave: The subscriptions to save. - subscriptionIDsToDelete: The identifiers of the subscriptions to permanently delete. - Returns: A tuple with the following named elements: - term `saveResults`: A dictionary of saved subscriptions. The dictionary uses the identifiers of the subscriptions you specify in `subscriptionsToSave` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding modified subscription (as it appears on the server), or an error that describes why CloudKit can't modify that subscription. - term `deleteResults`: A dictionary of deleted subscriptions. The dictionary uses the identifiers you specify in `subscriptionIDsToDelete` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either <doc://com.apple.documentation/documentation/swift/void> to indicate a successful deletion, or an error that describes why CloudKit can't delete that subscription. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account; otherwise, the returned tuple includes any individual subscription errors. For information on a more configurable way to modify subscriptions, see ``CKModifySubscriptionsOperation``.

method · iOS 15.0+

fetchDatabaseChanges

TypeScript
fetchDatabaseChanges(changeToken: (CKServerChangeToken) | null, resultsLimit: (number) | null, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func fetchDatabaseChanges(since changeToken: CKServerChangeToken?, resultsLimit: Int? = nil, completionHandler: @escaping @Sendable (Result<(modifications: [CKDatabase.DatabaseChange.Modification], deletions: [CKDatabase.DatabaseChange.Deletion], changeToken: CKServerChangeToken, moreComing: Bool), any Error>) -> Void)

Fetches all modified record zones and delivers them to a completion handler. - Parameters: - changeToken: The change token from the previous execution of this method. If this is your app's first fetch, or you want to refetch every change in the database's history, specify `nil`. - resultsLimit: The maximum number of changes to return. The server may use a limit lower than this value. - completionHandler: The closure to execute with the fetch results. The completion handler takes a single <doc://com.apple.documentation/documentation/swift/result> parameter that contains either a tuple, or an error if the request fails. For example, when the network is unavailable or the device doesn't have an active iCloud account. When present, the tuple contains the following named elements: - term `modifications`: An array of database modifications that occur after the time that `changeToken` denotes. Each modification contains details about a modified record zone. - term `deletions`: An array of database deletions that occur after the time that `changeToken` denotes. Each deletion contains details about a deleted or purged record zone. - term `changeToken`: The change token that corresponds to the fetch results' most recent change. - term `moreComing`: A Boolean value that indicates whether the server has additional changes for you to fetch. This method fetches record zone changes in a database, which includes new record zones, changed zones — including deleted or purged zones — and zones that contain record changes. Along with the fetched changes, CloudKit supplies a _change token_, which is an opaque token that denotes a specific point in the database's history. Store this token and provide it the next time you execute this method. Change tokens conform to <doc://com.apple.documentation/documentation/foundation/nssecurecoding> and are safe to cache on-disk. Don't infer any behavior or order from a token's contents. For information on a more configurable way to fetch database changes, see ``CKFetchDatabaseChangesOperation``.

method · iOS 15.0+

fetchRecordZoneChanges

TypeScript
fetchRecordZoneChanges(zoneID: CKRecordZone_ID, changeToken: (CKServerChangeToken) | null, desiredKeys: (Array<string>) | null, resultsLimit: (number) | null, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func fetchRecordZoneChanges(inZoneWith zoneID: CKRecordZone.ID, since changeToken: CKServerChangeToken?, desiredKeys: [CKRecord.FieldKey]? = nil, resultsLimit: Int? = nil, completionHandler: @escaping @Sendable (Result<(modificationResultsByID: [CKRecord.ID : Result<CKDatabase.RecordZoneChange.Modification, any Error>], deletions: [CKDatabase.RecordZoneChange.Deletion], changeToken: CKServerChangeToken, moreComing: Bool), any Error>) -> Void)

Fetches all modified records from a specific record zone and delivers them to a completion handler. - Parameters: - zoneID: The identifier of the record zone with changes. - changeToken: The change token from the previous execution of this method. If this is your app's first fetch, or you want to refetch every change in the record zone's history, specify `nil`. - desiredKeys: The fields to include on each fetched record. To include all fields, specify `nil`; to fetch only system fields, specify an empty array. - resultsLimit: The maximum number of changes to return. The server may use a limit lower than this value. - completionHandler: The closure to execute with the fetch results. The completion handler takes a single <doc://com.apple.documentation/documentation/swift/result> parameter that contains either a tuple, or an error if the request fails. For example, when the network is unavailable or the device doesn't have an active iCloud account. When present, the tuple contains the following named elements: - term `modificationResultsByID`: A dictionary of record modifications that occur after the time that `changeToken` denotes. The dictionary uses the identifiers of modified records as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding modification, or an error that describes why CloudKit can't provide that information. - term `deletions`: An array of record deletions that occur after the time that `changeToken` denotes. Each deletion contains details about a deleted record. - term `changeToken`: The change token that corresponds to the fetch results' most recent change. - term `moreComing`: A Boolean value that indicates whether the server has additional changes for you to fetch. This method fetches record changes in the specified record zone, such as those that occur during record creation, modification, and deletion. Along with the fetched changes, CloudKit supplies a _change token_, which is an opaque token that denotes a specific point in the record zone's history. Store this token and provide it the next time you execute this method. Change tokens conform to <doc://com.apple.documentation/documentation/foundation/nssecurecoding> and are safe to cache on-disk. Don't infer any behavior or order from a token's contents. For information on a more configurable way to fetch record zone changes, see ``CKFetchRecordZoneChangesOperation``.

method · iOS 15.0+

save

TypeScript
save(zone: CKRecordZone): Promise<CKRecordZone>
Swift declaration
func save(_ zone: CKRecordZone) async throws -> CKRecordZone

Saves a specific record zone. - Parameters: - zone: The record zone to save. - Returns: The saved record zone (as it appears on the server). This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account. For information on a more convenient way to save record zones, see ``CKDatabase/modifyRecordZones(saving:deleting:)``.

method · iOS 15.0+

save

TypeScript
save87972(subscription: CKSubscription): Promise<CKSubscription>
Swift declaration
func save(_ subscription: CKSubscription) async throws -> CKSubscription

Saves a specific subscription. - Parameters: - subscription: The subscription to save. - Returns: The saved subscription (as it appears on the server). This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account. For information on a more convenient way to save subscriptions, see ``CKDatabase/modifySubscriptions(saving:deleting:)``.

method · iOS 15.0+

save

TypeScript
save91437(record: CKRecord): Promise<CKRecord>
Swift declaration
func save(_ record: CKRecord) async throws -> CKRecord

Saves a specific record. - Parameters: - record: The record to save. - Returns: The saved record (as it appears on the server) The save succeeds only when the specified record is new, or is a more recent version than the one on the server. For information on a more convenient way to save records, see ``CKDatabase/modifyRecords(saving:deleting:savePolicy:atomically:)``.

method · iOS 15.0+

fetch

TypeScript
fetchWithCursorDesiredKeysResultsLimitCompletionHandler(queryCursor: CKQueryOperation_Cursor, desiredKeys: (Array<string>) | null, resultsLimit: number, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func fetch(withCursor queryCursor: CKQueryOperation.Cursor, desiredKeys: [CKRecord.FieldKey]? = nil, resultsLimit: Int = CKQueryOperation.maximumResults, completionHandler: @escaping @Sendable (Result<(matchResults: [(CKRecord.ID, Result<CKRecord, any Error>)], queryCursor: CKQueryOperation.Cursor?), any Error>) -> Void)

Retrieves the next batch of records from an existing search and delivers them to a completion handler. - Parameters: - queryCursor: The cursor that identifies, within the full search results, the location of the next subset of results to retrieve. - desiredKeys: The fields to include on each fetched record. To include all fields, specify `nil`; to fetch only system fields, specify an empty array. - resultsLimit: The maximum number of records to return in a single set of results. - completionHandler: The closure to execute with the search results. The completion handler takes a single <doc://com.apple.documentation/documentation/swift/result> parameter that contains either a tuple, or an error if the request fails. For example, when the network is unavailable or the device doesn't have an active iCloud account. When present, the tuple contains the following named elements: - term `matchResults`: An array of tuples. Each tuple includes a record identifier and a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding matched record, or an error that describes why CloudKit can't provide that record. For example, if CloudKit fails to materialize an asset field, it returns an error instead of a partial record. CloudKit sorts the array according to the query's sort descriptors. - term `queryCursor`: A cursor if the number of results exceeds `resultsLimit`; otherwise, `nil`. If you specify `resultsLimit` and the number of matched records exceeds that value, CloudKit provides only that number of records and a _cursor_ — an object that marks a specific location in the full search results. To retrieve the next subset of search results, execute this method again and pass the provided cursor from previous execution. For information on a more configurable way to search a database, see ``CKQueryOperation``.

method · iOS 15.0+

fetch

TypeScript
fetchWithRecordIDsDesiredKeysCompletionHandler(recordIDs: Array<CKRecord_ID>, desiredKeys: (Array<string>) | null, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func fetch(withRecordIDs recordIDs: [CKRecord.ID], desiredKeys: [CKRecord.FieldKey]? = nil, completionHandler: @escaping @Sendable (Result<[CKRecord.ID : Result<CKRecord, any Error>], any Error>) -> Void)

Fetches the specified records and delivers them to a completion handler. - Parameters: - recordIDs: The identifiers of the records to fetch. - desiredKeys: The fields to include on each fetched record. To include all fields, specify `nil`; to fetch only system fields, specify an empty array. - completionHandler: The closure to execute with the fetch results. The completion handler takes the following parameters: - A <doc://com.apple.documentation/documentation/swift/result> that contains either a dictionary of fetched records, or an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account. When present, the dictionary uses the identifiers you specify in `recordIDs` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding fetched record, or an error that describes why CloudKit can't provide that record. If you're fetching records of different types, make sure that `desiredKeys` is the union of all the fields you require across each distinct record type. For information on a more configurable way to fetch specific records, see ``CKFetchRecordsOperation``.

method · iOS 15.0+

fetch

TypeScript
fetchWithRecordZoneIDsCompletionHandler(zoneIDs: Array<CKRecordZone_ID>, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func fetch(withRecordZoneIDs zoneIDs: [CKRecordZone.ID], completionHandler: @escaping @Sendable (Result<[CKRecordZone.ID : Result<CKRecordZone, any Error>], any Error>) -> Void)

Fetches the specified record zones and delivers them to a completion handler. - Parameters: - zoneIDs: The identifiers of the record zones to fetch. - completionHandler: The closure to execute with the fetch results. The completion handler takes the following parameters: - A <doc://com.apple.documentation/documentation/swift/result> that contains either a dictionary of fetched record zones, or an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account. When present, the dictionary uses the identifiers you specify in `zoneIDs` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding fetched record zone, or an error that describes why CloudKit can't provide that record zone. For information on a more configurable way to fetch specific record zones, see ``CKFetchRecordZonesOperation``.

method · iOS 8.0+

fetch

TypeScript
fetchWithSubscriptionIDCompletionHandler(subscriptionID: string, completionHandler: ((arg0: (CKSubscription) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
@preconcurrency func fetch(withSubscriptionID subscriptionID: CKSubscription.ID, completionHandler: @escaping @Sendable (CKSubscription?, (any Error)?) -> Void)

Fetches a specific subscription and delivers it to a completion handler. - Parameters: - subscriptionID: The identifier of the subscription to fetch. - completionHandler: The closure to execute with the fetch results. The completion handler takes the following parameters: - The requested subscription, or `nil` if CloudKit can't provide that subscription. - An error if a problem occurs, or `nil` if the fetch completes successfully. For information on a more convenient way to fetch specific subscriptions, see ``CKDatabase/subscriptions(for:)``.

method · iOS 15.0+

fetch

TypeScript
fetchWithSubscriptionIDsCompletionHandler(subscriptionIDs: Array<string>, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func fetch(withSubscriptionIDs subscriptionIDs: [CKSubscription.ID], completionHandler: @escaping @Sendable (Result<[CKSubscription.ID : Result<CKSubscription, any Error>], any Error>) -> Void)

Fetches the specified subscriptions and delivers them to a completion handler. - Parameters: - subscriptionIDs: The identifiers of the subscriptions to fetch. - completionHandler: The closure to execute with the fetch results. The completion handler takes the following parameters: - A <doc://com.apple.documentation/documentation/swift/result> that contains either a dictionary of fetched subscriptions, or an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account. When present, the dictionary uses the identifiers you specify in `subscriptionIDs` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding fetched subscription, or an error that describes why CloudKit can't provide that subscription. For information on a more configurable way to fetch specific subscriptions, see ``CKFetchSubscriptionsOperation``.

method · iOS 15.0+

fetch

TypeScript
fetchWithQueryInZoneWithDesiredKeysResultsLimitCompletionHandler(query: CKQuery, zoneID: (CKRecordZone_ID) | null, desiredKeys: (Array<string>) | null, resultsLimit: number, completionHandler: ((arg0: SDKHandle) => void)): void
Swift declaration
@preconcurrency func fetch(withQuery query: CKQuery, inZoneWith zoneID: CKRecordZone.ID? = nil, desiredKeys: [CKRecord.FieldKey]? = nil, resultsLimit: Int = CKQueryOperation.maximumResults, completionHandler: @escaping @Sendable (Result<(matchResults: [(CKRecord.ID, Result<CKRecord, any Error>)], queryCursor: CKQueryOperation.Cursor?), any Error>) -> Void)

Searches for records that match a predicate and delivers them to a completion handler. - Parameters: - query: The query that contains the search parameters. For more information, see ``CKQuery``. - zoneID: The identifier of the record zone to search. If you're searching a shared database, provide a record zone identifier; otherwise, you can specify `nil` to search all record zones in the database. - desiredKeys: The fields to include on each fetched record. To include all fields, specify `nil`; to fetch only system fields, specify an empty array. - resultsLimit: The maximum number of records to return in a single set of results. - completionHandler: The closure to execute with the search results. The completion handler takes a single <doc://com.apple.documentation/documentation/swift/result> parameter that contains either a tuple, or an error if the request fails. For example, when the network is unavailable or the device doesn't have an active iCloud account. When present, the tuple contains the following named elements: - term `matchResults`: An array of tuples. Each tuple includes a record identifier and a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding matched record, or an error that describes why CloudKit can't provide that record. For example, if CloudKit fails to materialize an asset field, it returns an error instead of a partial record. CloudKit sorts the array according to the query's sort descriptors. - term `queryCursor`: A cursor if the number of results exceeds `resultsLimit`; otherwise, `nil`. If you specify `resultsLimit` and the number of matched records exceeds that value, CloudKit provides only that number of records and a _cursor_ — an object that marks a specific location in the full search results. To retrieve the next subset of search results, pass that cursor to the ``CKDatabase/fetch(withCursor:desiredKeys:resultsLimit:completionHandler:)`` method. For information on a more configurable way to search a database, see ``CKQueryOperation``.

method · iOS 8.0+

delete

TypeScript
deleteWithSubscriptionIDCompletionHandler(subscriptionID: string, completionHandler: ((arg0: (string) | null, arg1: (NativeError) | null) => void)): void
Swift declaration
@preconcurrency func delete(withSubscriptionID subscriptionID: CKSubscription.ID, completionHandler: @escaping @Sendable (String?, (any Error)?) -> Void)

Deletes a specific subscription and delivers the deleted subscription's identifier to a completion handler. - Parameters: - subscriptionID: The identifier of the subscription to delete. - completionHandler: The closure to execute after CloudKit deletes the subscription. The completion handler takes the following parameters: - The identifier of the deleted subscription, or `nil` if there's an error. - An error if a problem occurs, or `nil` if CloudKit successfully deletes the subscription. For information on a more convenient way to delete subscriptions, see ``CKDatabase/modifySubscriptions(saving:deleting:)``.

method · iOS 15.0+

record

TypeScript
record(recordID: CKRecord_ID): Promise<CKRecord>
Swift declaration
func record(for recordID: CKRecord.ID) async throws -> CKRecord

Fetches a specific record. - Parameters: - recordID: The identifier of the record to fetch. - Returns: The requested record. This method throws an error if the record cannot be found or if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account. For information on a more convenient way to fetch specific records, see ``CKDatabase/records(for:desiredKeys:)``.

method · iOS 15.0+ · Deprecated in iOS 15.0

perform

TypeScript
performInZoneWith(query: CKQuery, zoneID?: (CKRecordZone_ID) | null): Promise<Array<CKRecord>>
Swift declaration
func perform(_ query: CKQuery, inZoneWith zoneID: CKRecordZone.ID?) async throws -> [CKRecord]

Searches for records matching a predicate in the specified record zone. - Parameters: - query: The query that contains the search parameters. For more information, see ``CKQuery``. - zoneID: The identifier of the record zone to search. If you're searching a shared database, provide a record zone identifier; otherwise, you can specify `nil` to search all record zones in the database. - Returns: The records that match the specified query. For information on a more convenient way to search a database, see ``CKDatabase/records(matching:inZoneWith:desiredKeys:resultsLimit:)``.

method · iOS 15.0+

records

TypeScript
recordsContinuingMatchFromDesiredKeysResultsLimit(queryCursor: CKQueryOperation_Cursor, desiredKeys?: (Array<string>) | null, resultsLimit?: number): Promise<{ "matchResults": Array<[CKRecord_ID, SDKHandle]>; "queryCursor": (CKQueryOperation_Cursor) | null }>
Swift declaration
func records(continuingMatchFrom queryCursor: CKQueryOperation.Cursor, desiredKeys: [CKRecord.FieldKey]? = nil, resultsLimit: Int = CKQueryOperation.maximumResults) async throws -> (matchResults: [(CKRecord.ID, Result<CKRecord, any Error>)], queryCursor: CKQueryOperation.Cursor?)

Retrieves the next batch of records from an existing search and returns them to an awaiting caller. - Parameters: - queryCursor: The cursor that identifies, within the full search results, the location of the next subset of results to retrieve. - desiredKeys: The fields to include on each fetched record. To include all fields, specify `nil`; to fetch only system fields, specify an empty array. - resultsLimit: The maximum number of records to return in a single set of results. - Returns: A tuple with the following named elements: - term `matchResults`: An array of tuples. Each tuple includes a record identifier and a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding matched record, or an error that describes why CloudKit can't provide that record. For example, if CloudKit fails to materialize an asset field, it returns an error instead of a partial record. CloudKit sorts the array according to the query's sort descriptors. - term `queryCursor`: A cursor if the number of results exceeds `resultsLimit`; otherwise, `nil`. If you specify `resultsLimit` and the number of matched records exceeds that value, this method returns only that number of records and a _cursor_ — an object that marks a specific location in the full search results. To retrieve the next subset of search results, execute this method again and pass the returned cursor from previous execution. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account; otherwise, the returned tuple includes any individual record errors. For information on a more configurable way to search a database, see ``CKQueryOperation``.

method · iOS 15.0+

records

TypeScript
recordsForDesiredKeys(ids: Array<CKRecord_ID>, desiredKeys?: (Array<string>) | null): Promise<NativeMap<CKRecord_ID, SDKHandle>>
Swift declaration
func records(for ids: [CKRecord.ID], desiredKeys: [CKRecord.FieldKey]? = nil) async throws -> [CKRecord.ID : Result<CKRecord, any Error>]

Fetches the specified records and returns them to an awaiting caller. - Parameters: - ids: The identifiers of the records to fetch. - desiredKeys: The fields to include on each fetched record. To include all fields, specify `nil`; to fetch only system fields, specify an empty array. - Returns: A dictionary that contains the fetched records. The dictionary uses the identifiers you specify in `ids` as its keys. The value of each key is a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding fetched record, or an error that describes why CloudKit can't provide that record. If you're fetching records of different types, make sure that `desiredKeys` is the union of all the fields you require across each distinct record type. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account; otherwise, the returned dictionary includes any individual record errors. For information on a more configurable way to fetch specific records, see ``CKFetchRecordsOperation``.

method · iOS 15.0+

records

TypeScript
recordsMatchingInZoneWithDesiredKeysResultsLimit(query: CKQuery, zoneID?: (CKRecordZone_ID) | null, desiredKeys?: (Array<string>) | null, resultsLimit?: number): Promise<{ "matchResults": Array<[CKRecord_ID, SDKHandle]>; "queryCursor": (CKQueryOperation_Cursor) | null }>
Swift declaration
func records(matching query: CKQuery, inZoneWith zoneID: CKRecordZone.ID? = nil, desiredKeys: [CKRecord.FieldKey]? = nil, resultsLimit: Int = CKQueryOperation.maximumResults) async throws -> (matchResults: [(CKRecord.ID, Result<CKRecord, any Error>)], queryCursor: CKQueryOperation.Cursor?)

Searches for records that match a predicate and returns them to an awaiting caller. - Parameters: - query: The query that contains the search parameters. For more information, see ``CKQuery``. - zoneID: The identifier of the record zone to search. If you're searching a shared database, provide a record zone identifier; otherwise, you can specify `nil` to search all record zones in the database. - desiredKeys: The fields to include on each fetched record. To include all fields, specify `nil`; to fetch only system fields, specify an empty array. - resultsLimit: The maximum number of records to return in a single set of results. - Returns: A tuple with the following named elements: - term `matchResults`: An array of tuples. Each tuple includes a record identifier and a <doc://com.apple.documentation/documentation/swift/result> that contains either the corresponding matched record, or an error that describes why CloudKit can't provide that record. For example, if CloudKit fails to materialize an asset field, it returns an error instead of a partial record. CloudKit sorts the array according to the query's sort descriptors. - term `queryCursor`: A cursor if the number of results exceeds `resultsLimit`; otherwise, `nil`. If you specify `resultsLimit` and the number of matched records exceeds that value, this method returns only that number of records and a _cursor_ — an object that marks a specific location in the full search results. To retrieve the next subset of search results, pass that cursor to the ``CKDatabase/records(continuingMatchFrom:desiredKeys:resultsLimit:)`` method. This method throws an error if the request fails, such as when the network is unavailable or the device doesn't have an active iCloud account; otherwise, the returned tuple includes any individual record errors. For information on a more configurable way to search a database, see ``CKQueryOperation``.

method · iOS 15.0+ · Deprecated in iOS 15.0

records

TypeScript
recordsMatchingInZoneWith(query: CKQuery, zoneID?: (CKRecordZone_ID) | null): Promise<Array<CKRecord>>
Swift declaration
func records(matching query: CKQuery, inZoneWith zoneID: CKRecordZone.ID?) async throws -> [CKRecord]

Searches for records in the specified record zone and returns them to an awaiting caller. @DeprecationSummary { Use ``CKDatabase/records(matching:inZoneWith:desiredKeys:resultsLimit:)`` instead. } - Parameters: - query: The query that contains the search parameters. For more information, see ``CKQuery``. - zoneID: The identifier of the record zone to search. If you're searching a shared database, provide a record zone identifier; otherwise, you can specify `nil` to search all record zones in the database. - Returns: An array of records that match the specified query. For information on a more configurable way to search a database, see ``CKQueryOperation``.

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

CKDatabase.init()

inherited init: clang: 'init' is unavailable

All CloudKit types →