Perform(_:inZoneWith:completionHandler:) 已弃用?或不?iOS 15

Lka*_*abo 6 cloudkit ios15 xcode13

在 iOS 15 的 Xcode 13 beta 中,我收到一条消息,称perform(_:inZoneWith:completionHandler:)(CloudKit) 在 iOS 15 中已弃用并重命名为fetchRecords(matching:inZoneWith:desiredKeys:resultsLimit:completionHandler:)“但是...”

  1. Apple 文档网站未声明此方法已弃用:https://developer.apple.com/documentation/cloudkit/ckdatabase/1449127-perform

  2. Apple 正在展示 iOS 15 的其他弃用(另一种方法):https://developer.apple.com/documentation/cloudkit/ckdatabase/3794331-records/

  3. fetchRecords(matching:inZoneWith:desiredKeys:resultsLimit:completionHandler:)似乎不存在..还..( Value of type 'CKDatabase' has no member 'fetchRecords')

那么,这是否只是一个错误消息,因为它是测试版?我应该担心重写使用的函数perform(_:inZoneWith:completionHandler:)吗?

这是我的函数,我尝试将其改编为 fetchRecords,但它不存在。我尝试适应它,fetch(withQuery:completionHandler:但我有点迷失让它发挥作用..

(该函数只是从iCloud私有数据库中删除记录):

        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
                    }
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

任何见解表示赞赏..

谢谢

更新 我会说,是的,这似乎是一个错误,或者至少是一个过早的消息,但是,在重写 async/await 的代码之后,它更加干净且易于阅读。对于那些努力弄清楚这一点的人,这里是上面的代码转换为 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)
        }

}
Run Code Online (Sandbox Code Playgroud)

Mik*_*ane 4

我在 beta 5 中,仍然收到此警告,但该方法尚未实现,因此看起来他们并没有弃用旧方法,只是忘记删除警告。几天后我们就会得到 Xcode 的最终版本。

更新:看起来犯了一个错误。新方法不称为 fetchedRecords(),而是称为records() https://developer.apple.com/documentation/cloudkit/ckdatabase/3856524-records