CKFetchRecordsOperation perRecordCompletionBlock Not Returning Error
<p>I have a strange problem with part of my app's <code>CloudKit</code> code.  I have a list of <code>CKRecordID</code> objects stored within my app that eventually I need to update. Normally I just use the <code>CKFetchRecordsOperation</code> with the <code>perRecordCompletionBlock</code> to fetch the individual records and then handle them accordingly.  Under normal circumstances that works fine. My problem arises when the user isn't connected to the cloud, or say their network is down. It's not that it's crashing or anything, it's just not handling the error at all. One of the reasons I need to handle the error properly, is that before the data starts to refresh, I show a loading view to notify the user of the update. Then when the fetch is complete, I have a delegate callback to notify the original <code>ViewController</code> the process is done and remove the loading view.  I realized that this could cause a problem if a user is not connected to a network, so I tried to insert code to send the callback when an error is handled. The problem is that when I disconnect my test device from any network, it attempts the fetch but never even handles the error. Here is the basic code I'm using:</p>

<pre><code> let recordIDs:[CKRecordID] = //Saved ID's
 let fetch = CKFetchRecordsOperation(recordIDs: recordIDs)
 fetch.perRecordCompletionBlock = { (record:CKRecord?, recordID:CKRecordID?, error: NSError?) in

        if error != nil {

             // I've inserted breakpoints here and this never gets
             // handled once I turn wifi off, or disable iCloud                 

             dispatch_async(dispatch_get_main_queue()) {
                  self.customDelegate.errorRefreshingRecords()
             }

        }
        else if let record = record {

             // Here I would handle the record should it fetch properly
             // this works great when the device is connected to the cloud.

        }

 }
 if let database = self.publicDatabase {
     fetch.database = database
     fetch.start()
 }
</code></pre>

<p>Can anybody tell me if I am doing something wrong with the error handling?  When I do the same similar concept, but use the <code>fetchRecordWithID</code> operation, the error gets handled.  I don't understand why this would work any different.  Like I mentioned in the comments, I've tried inserting breakpoints, and the code just never makes it there. Does this <code>perRecordCompletionBlock</code> not work at all without some kind of communication with the cloud servers? </p>

<p>Any help at all would be appreciated.</p>

<p>Thanks!</p>