Get partial errors from NSError

When using CloudKit, an error is sometimes returned PartialFailure

, which could be caused by duplicate subscriptions, etc. See example below.

<CKError 0x7f8318711520: "Partial Failure" (2/1011); 
"Failed to modify some subscriptions"; uuid = A434B010-7650-4BBA-8A7A-33CD0690FD15; 
container ID = "iCloud.xxx.xxx"; partial errors: { 
EFC65F4A-A595-44A3-A022-323D9CE9B535 = <CKError 0x7f831a007be0: "Server Rejected Request" (15/2032); server message = "subscription is duplicate of '_930081460_AA87A676-DE57-4530-8BB8-7465BF4F4303'"> 
C4913907-28F3-42DB-8455-9966D9084834 = <CKError 0x7f83185cfc20: "Server Rejected Request" (15/2032); server message = "subscription is duplicate of '_930081460_F92FA91D-3E92-4E46-AE59-E912F8871026'"> }>

      

I want to get these partial errors from the main error object, but I don't know how. NSError

has no property partialError

, and it has no key in userInfo

order to get it.

+3


source to share


2 answers


You don't go back straight to NSError

, you go back to CKError

. Looking at the documentation for CKError

, there is actually a key CKPartialErrorsByItemIDKey

. This is like the key that the CKErrors dictionary will return with the item id key if you ask me! The userInfo object must contain this key.

Also registered here



CloudKit Framework Constant Reference

+3


source


Two years later, and I still don't think that access to partial errors is particularly well documented. Thanks @Acey for putting me on the right track withCKPartialErrorsByItemIDKey

For those struggling, here's an example of how I got a partial error in CKModifySubscriptionsOperation

(Swift 2.2):



someZoneSubscriptionOperation.modifySubscriptionsCompletionBlock = {(savedSubscriptions: [CKSubscription]?, deletedSubscriptionIDs:[String]?, operationError:NSError?) in

    // check specifically for an error in changing subscriptions to custom zone with specific subscriptionID
    if let partialError = operationError?.userInfo[CKPartialErrorsByItemIDKey]?[subscriptionID] as? ErrorType {
        print(partialError)         // prints partial error for custom zone with `subscriptionID` if it exists
    }
}

      

+2


source







All Articles