Created
September 19, 2013 07:51
-
-
Save hsjunnesson/6620276 to your computer and use it in GitHub Desktop.
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
#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 |
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
#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 |
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)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