Andrew
Andrew

Reputation: 250

CKFetchRecordChangesOperation - moreComing

changesOperation.fetchRecordChangesCompletionBlock = ^(CKServerChangeToken *serverChangeToken, NSData *clientChangeTokenData, NSError *operationError){

    //encode and save token

    NSData *encodedServerChangeToken = [NSKeyedArchiver archivedDataWithRootObject:serverChangeToken];

    [[NSUserDefaults standardUserDefaults] setObject:encodedServerChangeToken forKey:fetchToken];

    [[NSUserDefaults standardUserDefaults] synchronize];



    //handle more - **this causes a retain cycle**
    if(changesOperation.moreComing){

    }

};

Hi just wondering in the fetchRecordChangesCompletionBlock, the docs say:

If the server is unable to deliver all of the changed results with this operation object, it sets this property to YES before executing the block in the fetchRecordChangesCompletionBlock property. To fetch the remaining changes, create a new CKFetchRecordChangesOperation object using the change token returned by the server.

In the code above this causes a retain cycle so how should this be handled and when recreating the operation is it possible to use the same completion blocks alreay created?

Upvotes: 4

Views: 1206

Answers (1)

Edwin Vermeer
Edwin Vermeer

Reputation: 13127

You should define a weak changesoperation like this

__weak CKFetchNotificationChangesOperation *weakChangesOperation = changesOperation;
changesOperation.fetchRecordChangesCompletionBlock = ^(CKServerChangeToken *serverChangeToken, NSData *clientChangeTokenData, NSError *operationError){
    ...
    if(weakChangesOperation.moreComing){
    }

Upvotes: 5

Related Questions