Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Created March 10, 2012 13:08
Show Gist options
  • Save Dimillian/2011391 to your computer and use it in GitHub Desktop.
Save Dimillian/2011391 to your computer and use it in GitHub Desktop.
Block ex
-(void)executeBlockRequest:(void (^)(NSJSONSerialization *, MSJSonError *))handler
{
[NSURLConnection sendAsynchronousRequest:[self constructRequest] queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *res, NSData *data, NSError *error){
NSJSONSerialization *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
if (error) {
MSJSonError *errorRest = [[MSJSonError alloc]init];
errorRest.name = error.description;
errorRest.name = error.description;
handler(json, errorRest);
}
else {
NSDictionary *dic = (NSDictionary *)json;
if ([dic objectForKey:@"errors"]) {
NSArray *errors = [dic objectForKey:@"errors"];
MSJSonError *errorRest = [[MSJSonError alloc]initWithDictionnary:[errors objectAtIndex:0]];
handler(json, errorRest);
}
else {
handler(json, nil);
}
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment