Created
June 21, 2015 22:08
-
-
Save alcedo/143ad1f3286d460dd395 to your computer and use it in GitHub Desktop.
sample code showing how to use mock JSON response
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
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