Skip to content

Instantly share code, notes, and snippets.

@hborders
Created January 25, 2014 05:42
Show Gist options
  • Select an option

  • Save hborders/8612342 to your computer and use it in GitHub Desktop.

Select an option

Save hborders/8612342 to your computer and use it in GitHub Desktop.
ARC block release-only block crash
- (AFHTTPRequestOperation *)operationForEmptyResponseRequest:(NSURLRequest*) request onComplete:(void(^)(void)) completeBlock onError:(void (^)(NSError *)) errorBlock {
void (^nilObjectCompleteBlock)(id);
if (complete) {
void (^heapCompleteBlock)(void) = [completeBlock copy];
// INTERESTING BITS:
// iOS7: this crashes in weird ways if we don't copy the block we assign to nilObjectComplete here.
// it is supposed to be safe to pass a block down into another block, but maybe not.
nilObjectCompleteBlock = [^(id nilObject) {
heapCompleteBlock();
} copy];
} else {
nilObjectCompleteBlock = NULL;
}
AFURLConnectionOperation operation = [AFURLConnectionOperation HTTPRequestOperationWithRequest:request
success:(^(AFHTTPRequestOperation *operation, id responseObject) {
if (nilObjectCompleteBlock) {
nilObjectCompleteBlock();
}
})
failure:(^(AFHTTPRequestOperation *operation, NSError *error) {
if (errorBlock) {
errorBlock(error);
}
})];
return operation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment