Skip to content

Instantly share code, notes, and snippets.

@malshash
Created February 12, 2017 01:53
Show Gist options
  • Save malshash/12fd9cdba99b0888b1276c41dc0e7165 to your computer and use it in GitHub Desktop.
Save malshash/12fd9cdba99b0888b1276c41dc0e7165 to your computer and use it in GitHub Desktop.
restkit example
#pragma mark - Network Accessibility Code
- (void)fetchData:(void(^)(void))completion {
[self prepareForFetch];
RestClientSuccessBlock onSuccess = ^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSDictionary *resultDict = [mappingResult dictionary];
dispatch_async(dispatch_get_main_queue(), ^{
[self handleResponse:resultDict error:nil];
[MBProgressHUD hideHUDForView:self.view animated:YES];
if(completion) {
completion();
}
});
};
RestClientFailureBlock onFailure = ^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Hit error: %@ with operation: %@", error.localizedDescription, operation);
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUDForView:self.view animated:YES];
[self handleResponse:nil error:error];
});
};
NSInteger offset = _currentPage * ListingLimit;
[[ListingsClient sharedInstance] fetchListingsWithLimit:ListingLimit offset:offset success:onSuccess failure:onFailure completion:completion];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment