-1

我在 SO 和 Google 中查看并查看了使用此方法的示例:

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

并且无法使语法正确。这就是我所拥有的:

//    [[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;
}];

第一行是我要替换的(在 MagicalRecord 2.2 中已弃用)。这是我在第 2 行遇到的语法错误:

不兼容的块指针类型将“void (^)(__autoreleasing MRSaveCompletionHandler *)”发送到“MRSaveCompletionHandler”类型的参数(又名“void (^)(BOOL, NSError *__strong)”)

正确的语法应该是什么?

4

1 回答 1

1

MRSaveCompletionHandlertypedef一个块类型,在这里定义。您将它用作块的参数。代码应如下所示:

[localContext MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
    // Your code
}];
于 2013-12-14T19:54:49.070 回答