Created
January 25, 2014 05:42
-
-
Save hborders/8612342 to your computer and use it in GitHub Desktop.
ARC block release-only block crash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (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