Skip to content

Instantly share code, notes, and snippets.

@fjcaetano
Created June 3, 2013 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjcaetano/5700381 to your computer and use it in GitHub Desktop.
Save fjcaetano/5700381 to your computer and use it in GitHub Desktop.
Return methods definition protocol at the and of a request using AFNetworking.
//
// AFNetworkingOperationDelegate.h
//
// Created by Flávio Caetano on 12/12/12.
// Copyright (c) 2012 FlávioCaetano.com.
//
#import <Foundation/Foundation.h>
#define COMPLETION_BLOCK(delegate) ^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){[delegate requestDidFinish:request withResponse:response andJSON:JSON];}
#define ERROR_BLOCK(delegate) ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){[delegate requestDidFail:request withResponse:response error:error andJSON:JSON];}
//#define COMPLETION(delegate) ^(AFHTTPRequestOperation * operation){}
/** Return methods definition protocol at the and of a request using AFNetworking.
Defined macros:
- **COMPLETION_BLOCK(delegate)**: alias to the success block provided to the AFNetworking request.
- **ERROR_BLOCK(delegate)**: alias to the fail block providede to the AFNetworking request.
*/
@protocol AFNetworkingOperationDelegate <NSObject>
/** Method called at the end of the request in case of success.
@param request NSURLRequest sent with the request's call.
@param response NSHTTPURLResponse with the request's response data.
@param JSON `id` with the JSON object.
*/
- (void)requestDidFinish:(NSURLRequest *)request withResponse:(NSHTTPURLResponse *)response andJSON:(id)JSON;
/** Method called at the end of the request if failed.
@param request NSURLRequest sent with the request's call.
@param response NSHTTPURLResponse with the request's response data.
@param error NSError the occurred error.
@param JSON `id` with the JSON object.
*/
- (void)requestDidFail:(NSURLRequest *)request withResponse:(NSHTTPURLResponse *)response error:(NSError *)error andJSON:(id)JSON;
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment