Created
October 19, 2011 07:43
-
-
Save ericflo/1297693 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
// | |
// NSURLConnection+Blocks.h | |
// SteveHolt | |
// | |
// Created by Eric Florenzano on 10/19/11. | |
// Copyright (c) 2011 Boilerplate Inc. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSURLConnection (Blocks) | |
#pragma mark Class API Extensions | |
+ (void)asyncRequest:(NSURLRequest *)request | |
success:(void(^)(NSData *, NSURLResponse *))successBlock_ | |
failure:(void(^)(NSData *, NSError *))failureBlock_; | |
@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
// | |
// NSURLConnection+Blocks.m | |
// SteveHolt | |
// | |
// Created by Eric Florenzano on 10/19/11. | |
// Copyright (c) 2011 Boilerplate Inc. All rights reserved. | |
// | |
#import "NSURLConnection+Blocks.h" | |
@implementation NSURLConnection (Blocks) | |
+ (void)asyncRequest:(NSURLRequest *)request | |
success:(void(^)(NSData *, NSURLResponse *))successBlock_ | |
failure:(void(^)(NSData *, NSError *))failureBlock_ { | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
NSURLResponse *response = nil; | |
NSError *error = nil; | |
NSData *data = [NSURLConnection sendSynchronousRequest:request | |
returningResponse:&response | |
error:&error]; | |
if(error) { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
failureBlock_(data, error); | |
}); | |
} else { | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
successBlock_(data, response); | |
}); | |
} | |
[pool release]; | |
}); | |
} | |
@end |
Thank you :)
…On Wed, Oct 19, 2011 at 5:12 AM, Cdric Luthi < ***@***.***>wrote:
You must test `if (!data)` instead of `if (error)`
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1297693
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You must test
if (!data)
instead ofif (error)