Skip to content

Instantly share code, notes, and snippets.

@malshash
Last active February 12, 2017 01:56
Show Gist options
  • Save malshash/35a54afc00f868022818d2b57ca9de50 to your computer and use it in GitHub Desktop.
Save malshash/35a54afc00f868022818d2b57ca9de50 to your computer and use it in GitHub Desktop.
restkit example
typedef void (^RestClientSuccessBlock)(RKObjectRequestOperation *operation, RKMappingResult *mappingResult);
typedef void (^RestClientFailureBlock)(RKObjectRequestOperation *operation, NSError *error);
#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