Question

I have looked and looked in SO and Google for an example use of this method:

MR_saveToPersistentStoreWithCompletion:

Asynchronously save changes in the current context all the way back to the persistent store
- (void)MR_saveToPersistentStoreWithCompletion:(MRSaveCompletionHandler)completion
Parameters

completion

Completion block that is called after the save has completed. The block is passed a success state as a BOOL and an NSError instance if an error occurs. Always called on the main queue.

Discussion

Executes asynchronous saves on the current context, and any ancestors, until the changes have been persisted to the assigned persistent store. The completion block will always be called on the main queue.
Declared In
NSManagedObjectContext+MagicalSaves.h

and am unable to get the syntax correct. This is what I have:

//    [[NSManagedObjectContext MR_contextForCurrentThread] MR_saveErrorHandler:^(NSError *error){  1.9.0

[localContext MR_saveToPersistentStoreWithCompletion:^(MRSaveCompletionHandler *completion) { //  store it...

    [localContext rollback];
    self.syncInProgress = NO;
    self.progressBlock = nil;
    self.progress = 0;

    [self handleError:error];
    return;
}];

The first line is what I'm replacing (it's deprecated in MagicalRecord 2.2). This is the syntax error I'm getting on line 2:

Incompatible block pointer types sending 'void (^)(__autoreleasing MRSaveCompletionHandler *)' to parameter of type 'MRSaveCompletionHandler' (aka 'void (^)(BOOL, NSError *__strong)')

What is the correct syntax supposed to be?

Was it helpful?

Solution

MRSaveCompletionHandler is a typedef for a block type, defined here. You're using it as a parameter to your block. The code should look like this:

[localContext MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
    // Your code
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top