Suppose I start a saveOperation using a CKModifyRecordsOperation object. Can I safely assume that the recordsToSave of the object will store the list of records given at start when I access it within the modifyRecordsCompletionBlock that is executed after the operation completes.
I would assume so, but then I saw this line in the Apple doc (basically not sure what they mean by "initial": The initial contents of the array are set to the records you specified in the initWithRecordsToSave:recordIDsToDelete: method. You can modify this array as needed before executing the operation.
If there are rare circumstances where it can change, then I want to go another way in my retry logic.
EDIT added code
CKModifyRecordsOperation *saveOperation = [[CKModifyRecordsOperation alloc] initWithRecordsToSave:recordsToSave recordIDsToDelete:nil] ;
saveOperation.modifyRecordsCompletionBlock = completionBlock ; //see completion block definition below
[self.publicDatabase addOperation:saveOperation] ;
[self.OperationQ addObject: saveOperation] ; //Saved in Q for later retrieval
completionBlock is defined as
^(NSArray *savedRecords, NSArray *deletedRecordIDs, NSError * operationError){
if(operationError)
{
DDLogError(@"Save of Touch event records failed with error %@",operationError) ;
//Retry, can I do this and safely assume first record retrieved here is the first record I inserted into original recordsToSave array
CKRecord *cardinalRecord = self.OperationQ[0].recordsToSave[0] ;
//Read a field from it to decide how to handle retry (e.g: retry after delay if important set of records, don't retry if not etc)..
}
else
{
//Handle success case
}
}
Based on the code you added to the question, it seems that you wish to retrieve the array of records originally passed to the modification operation.
Accessing self.OperationQ[0].recordsToSave
will certainly give you back the same array passed into [[CKModifyRecordsOperation alloc] initWithRecordsToSave:recordsToSave recordIDsToDelete:nil]
The message you reference from Apple's docs simply means that if your code updated the contents of recordsToSave
, it is safe to make those changes up until you call addOperation:
.
The operation won't ever change that array. So if you don't change it, then accessing it in the completion block will give you back exactly what you passed in originally.