Skip to content

Instantly share code, notes, and snippets.

@kcharwood
Last active December 12, 2015 07:49
Show Gist options
  • Save kcharwood/4739785 to your computer and use it in GitHub Desktop.
Save kcharwood/4739785 to your computer and use it in GitHub Desktop.
Custom AFOperation
-(void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *, id))success
failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure {
void (^newSuccessBlock)(AFHTTPRequestOperation*, id) =
^(AFHTTPRequestOperation *operation, id responseObject){
NSError * customError = nil;
//Do some custom error processessing
if(customError){
if(nil != failure)
failure(operation,customError);
}
else if( nil != success ) {
success(operation,responseObject);
}
};
void (^newFailureBlock)(AFHTTPRequestOperation*,NSError*)=
^(AFHTTPRequestOperation * operation, NSError * error){
//Check to see if the operation was cancelled so we don't call the failure
//This gives the same behavior as AFNetworking < 1.1.0
if(!self.isCancelled &&
nil != failure){
failure(operation,error);
}
};
[super setCompletionBlockWithSuccess:newSuccessBlock
failure:newFailureBlock];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment