Skip to content

Instantly share code, notes, and snippets.

@alcedo
Created June 21, 2015 22:08
Show Gist options
  • Save alcedo/143ad1f3286d460dd395 to your computer and use it in GitHub Desktop.
Save alcedo/143ad1f3286d460dd395 to your computer and use it in GitHub Desktop.
sample code showing how to use mock JSON response
NSString *mockResponse = @"{\
\"account_balance\": \"304.34\",\
\"bank_account_number\": \"03168943233\",\
\"bank_account_type\": \"POSB\",\
}";
NSError *jsonError;
NSData *objectData = [mockResponse dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingMutableContainers
error:&jsonError];
NSError *mappingError;
XPUser *user = [MTLJSONAdapter modelOfClass:XPUser.class fromJSONDictionary:json error:&mappingError];
if (mappingError && failure) {
failure(mappingError);
CLS_LOG(@"Error in XPHTTPClient getUserAccountDetails");
return;
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (success) {
success(user);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment