Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perform(_:inZoneWith:completionHandler:) deprecated? or not? iOS 15

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

  1. The Apple Docs website does not declare this method as deprecated: https://developer.apple.com/documentation/cloudkit/ckdatabase/1449127-perform

  2. Apple is showing other deprecations for iOS 15 (another method): https://developer.apple.com/documentation/cloudkit/ckdatabase/3794331-records/

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

}
like image 466
JerseyDevel Avatar asked Nov 06 '22 01:11

JerseyDevel


1 Answers

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

like image 100
Mikiko Jane Avatar answered Nov 17 '22 21:11

Mikiko Jane