Skip to content

Instantly share code, notes, and snippets.

@thiagoramos23
Created October 10, 2014 17:18
Show Gist options
  • Save thiagoramos23/a61f2154aac076147f5f to your computer and use it in GitHub Desktop.
Save thiagoramos23/a61f2154aac076147f5f to your computer and use it in GitHub Desktop.
JSPostAdapter.m
//
// JSPostAdapter.m
// JSONModelExample
//
// Created by Thiago Ramos on 10/9/14.
// Copyright (c) 2014 br.com.exemplo.jsonmodel. All rights reserved.
//
#define URL_POSTS @"http://10.1.1.101:3000/posts.json"
#import <AFNetworking/AFNetworking.h>
#import "JSPostAdapter.h"
#import "JSPost.h"
@implementation JSPostAdapter
- (void)getAllPosts
{
[[AFHTTPSessionManager manager] GET:URL_POSTS parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSError *error;
for (NSDictionary *result in responseObject) {
JSPost *post = [[JSPost alloc] initWithDictionary:result error:&error];
NSLog(@"%@", post);
NSLog(@"%@", error.description);
NSDictionary *dictionary = [post toDictionary];
NSLog(@"%@", dictionary);
NSString *jsonString = [post toJSONString];
NSLog(@"%@", jsonString);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"%@", error);
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment