0

我正在尝试创建一个接受完成处理程序块的包装器方法,该程序块又被传递给另一个完成处理程序。问题是,无论我做什么,我的完成处理程序都会在它被调用之前被释放。这是去除了大部分逻辑的方法。

+ (int) syncWithCompletion:(void (^)(NSError *error))completion;{
    //Copy the block argument and make it available to the block scope
    __block void (^completionBlock)(NSError *error) = [completion copy];
    // The is an AFNetworking operation
    [af.sharedHTTPClient enqueueBatchOfHTTPRequestOperations:syncOperations progressBlock:nil completionBlock:^(NSArray *operations) {
        // Call my copied block... but it's already been deallocated
        completionBlock(error);
    }];
    return somevariable;
}
4

1 回答 1

1

呸...代码因对完成处理程序为零的函数的另一个调用而死亡。这修复了它:

if(completionBlock){
    completionBlock(error);
}
于 2013-10-16T01:50:55.193 回答