Created
March 10, 2012 13:08
-
-
Save Dimillian/2011391 to your computer and use it in GitHub Desktop.
Block ex
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)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