Created
June 4, 2011 22:55
-
-
Save stuffmc/1008458 to your computer and use it in GitHub Desktop.
This file contains hidden or 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)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