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