Skip to content

Instantly share code, notes, and snippets.

@stuffmc
Created June 4, 2011 22:55
Show Gist options
  • Save stuffmc/1008458 to your computer and use it in GitHub Desktop.
Save stuffmc/1008458 to your computer and use it in GitHub Desktop.
+ (void)asyncRequest:(NSURLRequest *)request success:(void(^)(NSData *,NSURLResponse *))successBlock_ failure:(void(^)(NSData *,NSError *))failureBlock_
{
[[failureBlock_ copy] autorelease];
[[successBlock_ copy] autorelease];
[NSThread detachNewThreadSelector:@selector(backgroundSync:) toTarget:[NSURLConnection class]
withObject:[NSDictionary dictionaryWithObjectsAndKeys:
request,@"request",
successBlock_,@"success",
failureBlock_,@"failure",
nil]];
}
// See http://blog.logichigh.com/2010/09/12/cocoa-blocks/
[NSURLConnection asyncRequest:theRequest
success:^(NSData *data, NSURLResponse *response) {
[self performSelectorOnMainThread:@selector(fadeOut) withObject:nil waitUntilDone:YES];
}
failure:^(NSData *data, NSError *error) {
NSLog(@"Error! %@",[error localizedDescription]);
}];
}
- (void)fadeOut {
NSLog(@"yo");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment