【问题标题】:recovering errors with CKPartialErrorsByItemIDKey使用 CKPartialErrorsByItemIDKey 恢复错误
【发布时间】:2016-10-02 22:22:21
【问题描述】:

在得到.partialFailureCKError后,我一直在尝试恢复id和相应的错误,但是我遇到了问题......

我现在正在使用:

print("pE \(error.partialErrorsByItemID) or \(error.userInfo[CKPartialErrorsByItemIDKey])")

    if let dictionary = error.userInfo[CKPartialErrorsByItemIDKey] as? [NSObject: Error] {

print("partialErrors #\(dictionary.count)")    // <-- Not reaching this...

我还尝试了以下方法:

if let dictionary = error.partialErrorsByItemID {   // <-- error.pEBIID returns nil

和:

if let dictionary = error.userInfo[CKPartialErrorsByItemIDKey] as? [CKRecord : CKError /* and Error */] {    // <-- but neither triggers the if-let

第一个打印显示在控制台中(我将打开的标签向左切换,这样它们就不会被解释为 html):

pE nil or Optional({
">CKRecordID: 0x7b95ace0; CentralTableView:(_defaultZone:__defaultOwner__)>" = ">CKError 0x7a7e4cf0: \"Server Record Changed\" (14/2004); server message = \"record to insert already exists\"; uuid = B7AD7528-D8AE-4DCB-91FF-16B5271110F5; container ID = \"iCloud.com.yadayadayada\">";
})

据我了解,我应该从 userInfo 字典中返回 NSDictionary&lt;CKRecordID, (CK)Error&gt;CKPartialErrorsByItemIDKeyNSDictionary&lt;NSObject, Error&gt;partialErrorsByItemID 方法返回。根据第一次打印,该方法在这种情况下不起作用,但关键是给了我一个 CKRecordID 和 CKError 的字典。 我不明白为什么没有到达第二个印刷品?

【问题讨论】:

    标签: ios swift error-handling cloudkit ckerror


    【解决方案1】:

    根据文档,您得到的是 NSDictionary,而不是 Swift 字典。

    试试:

    if let dictionary = error.userInfo[CKPartialErrorsByItemIDKey] as? NSDictionary {
        print("partialErrors #\(dictionary.count)")
    }
    

    【讨论】:

      猜你喜欢
      • 2011-01-27
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多