In Xcode 13 beta for iOS 15, I am receiving a message that perform(_:inZoneWith:completionHandler:)
(CloudKit) is deprecated in iOS 15 and renamed to fetchRecords(matching:inZoneWith:desiredKeys:resultsLimit:completionHandler:)
However...
The Apple Docs website does not declare this method as deprecated: https://developer.apple.com/documentation/cloudkit/ckdatabase/1449127-perform
Apple is showing other deprecations for iOS 15 (another method): https://developer.apple.com/documentation/cloudkit/ckdatabase/3794331-records/
fetchRecords(matching:inZoneWith:desiredKeys:resultsLimit:completionHandler:)
does not seem to exist.. yet.. (Value of type 'CKDatabase' has no member 'fetchRecords'
)
So, is this just an incorrect message because its beta? Should I worry about rewriting a function that uses perform(_:inZoneWith:completionHandler:)
?
Here is my function, I've tried to adapt it to fetchRecords, but it does not exist. I tried adapting it to fetch(withQuery:completionHandler:
but I'm kind of lost getting it to work..
(This function just deletes records from the iCloud private database):
let container = CKContainer(identifier: "MyContainerNameHere")
let recordType = "DBName"
//delete all saved icloud records
let query = CKQuery(recordType: recordType, predicate: NSPredicate(value: true))
container.privateCloudDatabase.perform(query, inZoneWith: nil) { (rec, err) in
if let err = err {
print(err.localizedDescription)
completion(.failure(err))
return
}
guard let rec = rec else {
completion(.failure(CloudKitHelperError.castFailure))
return
}
for record in rec {
container.privateCloudDatabase.delete(withRecordID: record.recordID) { (recordId, err) in
if let err = err {
print(err.localizedDescription)
completion(.failure(err))
return
}
guard recordId != nil else {
completion(.failure(CloudKitHelperError.recordIDFailure))
return
}
}
}
}
Any insight appreciated..
Thx
Update I will say, that yes, this seems to be an error or at least a premature message, however, after rewriting the code for async/await, it is much cleaner and easier to read. For those struggling to figure this out, here is an example of the code above converted to Async/Await:
@MainActor func newDeleteCloudKit() async throws {
let container = CKContainer(identifier: "MyContainerNameHere")
let recordType = "DBName"
let query = CKQuery(recordType: recordType, predicate: NSPredicate(value: true))
let result = try await container.privateCloudDatabase.records(matching: query)
for record in result.0 {
try await container.privateCloudDatabase.deleteRecord(withID: record.0)
}
}
I'm in beta 5 and I still get this warning, but the method hasn't been implemented, so it looks like they are not deprecating the old one and just forgot to remove the warning. We should have the final version of Xcode in a few days.
UPDATE: It looks like the made a mistake. The new method is not called fetchedRecords(), it is called records() https://developer.apple.com/documentation/cloudkit/ckdatabase/3856524-records
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With