Last active
December 12, 2015 07:49
-
-
Save kcharwood/4739785 to your computer and use it in GitHub Desktop.
Custom AFOperation
This file contains 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
-(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