我无法完成此MagicalRecord方法调用的语法

时间:2013-12-14 19:23:21

标签: objective-c ios7 magicalrecord-2.2

我已经查看并在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)')

应该是什么样的正确语法?

1 个答案:

答案 0 :(得分:1)

对于块类型,

MRSaveCompletionHandlertypedef,定义为here。您正在将它用作块的参数。代码应如下所示:

[localContext MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
    // Your code
}];