Skip to content

Instantly share code, notes, and snippets.

@hsjunnesson
Created September 19, 2013 07:51
Show Gist options
  • Save hsjunnesson/6620276 to your computer and use it in GitHub Desktop.
Save hsjunnesson/6620276 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
typedef void(^SuccessBlock)(id object);
typedef void(^ErrorBlock)(NSString *error);
@interface JenkinsRequest : NSObject
@property (copy) SuccessBlock successBlock;
@property (copy) ErrorBlock errorBlock;
@end
#import "JenkinsRequest.h"
@implementation JenkinsRequest
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSXMLDocument * document = [[NSXMLDocument alloc] initWithData: receivedData options:0 error: nil];
id result = [translator translateDocument: document];
if (result == nil) {
if (self.errorBlock)
self.errorBlock(@"Document translation failed.");
}
else {
if (self.successBlock)
self.successBlock(result);
}
receivedData = nil;
}
@end
- (void)doStuff {
JenkinsRequest *request = [[JenkinsRequest alloc] init];
request.successBlock = ^ (id results) {
[self doStuffWithResults:results];
};
reuest.errorBlock = ^ (NSString *error) {
NSLog(@"Error! %@", error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment