or the Weary
No RestKit f
Matt Galloway
Architactile
matt@architactile.com
918-808-3072

Tuesday, January 28, 14
Some
Amazingly
Cool Data
from the
“Cloud”

ul* Web
RESTF es
Servic

the “Cloud”

REST-ish and JSONy.
ul,“ of course, I mean
* By “RESTF
Tuesday, January 28, 14
rvice Calls on iOS
Web Se
Define your URL
NSString *url = @”http://somewebservice.com/objects.json”;

Make the Call
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];

ese delegate methods!!!
Then implement all of th
-

(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
(void)connectionDidFinishLoading:(NSURLConnection *)connection

and now you have to parse
the JSON in NSData
into something useful...
Tuesday, January 28, 14
n is great, but...
NSJSONSerializatio
-(void) parseJSONIntoModel:(NSData *) jsonData {
NSError *error = nil;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONReadingAllowFragments
error:&error];
if (error!=nil) {
// TODO: Insert annoying JSON error handler here.
}
if ([json isKindOfClass:[NSArray class]]) {
//TODO: Uh. I was expecting a dictionary but apparently this is an array. Writng some handling code here.
}
for(NSString *key in [json allKeys]) {
if ([key isEqualToString:@"user"]) {
NSDictionary *userDictionary = [json objectForKey:key];
NSNumber *userId = [userDictionary objectForKey:@"id"];
RKGUser *user = [[ObjectFactory sharedFactory] userForUserId:userId];
if (user==nil) {
user = [[ObjectFactory sharedFactory] newUser];
user.userId=useriD;
}

}
.
.
.

user.name = [userDictionary objectForKey:@"name"];
user.username = [userDictionary objectForKey:@"username"];
user.phone = [userDictionary objectForKey:@"phone"];
user.email = [userDictionary objectForKey:@"email"];

Tuesday, January 28, 14
nter RestKit
E
https://github.com/RestK
it

/RestKit/

ing and modeling
ework for consum
RestKit is a fram
s on iOS and OS X
Tful web resource
RES

Tuesday, January 28, 14
[[RKObjectManager sharedManager] getObjectsAtPath:@"objects.json"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
// Call is successful. Objects are all populated.
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
// Call failed.
}];

Tuesday, January 28, 14
RestKit is...
rce & available on GitHub
* Open Sou
* Built on AFNetworking
Beautifully multi-threaded
*
eamlessly with CoreData
* Integrates s
o works with plain objects
* Als
lationships, nesting, etc.
* Handles re
on mapping like an ORM
* Based
* Very configurable
, POST, PATCH, etc.
ndles all REST verbs - GET
* Ha
y actively maintained
* Ver
ase seeding, search,
ch of other stuff - datab
* A bu n
XML, etc.
Tuesday, January 28, 14
ing RestKit
Install
I <3 CocoaPods
$ cd /path/to/MyProject
$ touch Podfile
$ edit Podfile
platform :ios, '5.0'
# Or platform :osx, '10.7'
pod 'RestKit', '~> 0.20.0'
$ pod install
$ open MyProject.xcworkspace

Tuesday, January 28, 14
Using RestKit: The W
e

Tuesday, January 28, 14

b Service
Using RestKit: The Object
@interface Joke : NSObject
@property (nonatomic, strong) NSNumber *jokeId;
@property (nonatomic, strong) NSString *text;
@end
@implementation Joke
@end

Tuesday, January 28, 14
Using RestKit: The Setup
-(void) setupRestKit {
RKObjectManager *objectManager =
[RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://api.icndb.com/"]];
objectManager.requestSerializationMIMEType=RKMIMETypeJSON;
[RKObjectManager setSharedManager:objectManager];
.
.
.

eps for CoreData, authentication, etc.)
(There are a few extra st

Tuesday, January 28, 14
Using RestKit: The Mappin
g
RKObjectMapping *jokeMapping = [RKObjectMapping mappingForClass:[Joke class]];
[jokeMapping addAttributeMappingsFromDictionary:@{
@"id":
@"joke":

@"jokeId",
@"text"}];

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor
responseDescriptorWithMapping:jokeMapping
method:RKRequestMethodGET
pathPattern:@"jokes"
keyPath:@"value"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];

Tuesday, January 28, 14
I <3 Singletons

a singleton, so
KObjectManager is
R
apping steps need
the setup and m
e, usually at app
only be done onc
launch.
it and forget it. :)
Se t

Tuesday, January 28, 14
Using RestKit: The Call
[[RKObjectManager sharedManager] getObjectsAtPath:@"jokes"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
self.jokes = mappingResult.array;
[self.tableView reloadData];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
[self displayError:error];
}];

RKMappingResult has
count,firstObject, array,
dictionary,
and set properties
Tuesday, January 28, 14
Using RestKit: The Mappin
gf

or POST

RKObjectMapping *inverseJokeMapping = [jokeMapping inverseMapping];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor
requestDescriptorWithMapping:inverseJokeMapping
objectClass:[Joke class]
rootKeyPath:@"jokes"
method:RKRequestMethodPOST ];
[[RKObjectManager sharedManager] addRequestDescriptor:requestDescriptor];

Tuesday, January 28, 14
it: POSTing
Using RestK
Joke *aJoke=[[Joke alloc] init];
aJoke.jokeId=@9999;
aJoke.text=@"Chuck Norris can find the end of a circle.";
[[RKObjectManager sharedManager] postObject:aJoke
path:@"jokes"
parameters:nil
success:^(RKObjectRequestOperation *operation,
RKMappingResult *mappingResult){}
failure:^(RKObjectRequestOperation *operation,
NSError *error){}];

Tuesday, January 28, 14
ome Demos
S

Tuesday, January 28, 14
Matt Galloway
Architactile
matt@architactile.com
918-808-3072

Tuesday, January 28, 14

More Related Content

PDF
Introduce leo-redundant-manager
PDF
Webinar - Centralising syslogs with the new beats, logstash and elasticsearch
PDF
Declare your infrastructure: InfraKit, LinuxKit and Moby
PDF
Puppet, now with google!
PPTX
PPTX
Couch to OpenStack: Glance - July, 23, 2013
PDF
Deploying Percona XtraDB Cluster in Openshift
PDF
Painless ruby deployment on shelly cloud
Introduce leo-redundant-manager
Webinar - Centralising syslogs with the new beats, logstash and elasticsearch
Declare your infrastructure: InfraKit, LinuxKit and Moby
Puppet, now with google!
Couch to OpenStack: Glance - July, 23, 2013
Deploying Percona XtraDB Cluster in Openshift
Painless ruby deployment on shelly cloud

What's hot (20)

PDF
Object Storage with Gluster
PDF
2013 PyCon SG - Building your cloud infrastructure with Python
PPTX
5. configuring multiple switch with files
PDF
Blockchain Workshop - Software Freedom Day 2017
PDF
Long Tail Treasure Trove
PDF
Pusherアプリの作り方
PDF
Node.js - A Quick Tour II
PPTX
StackExchange.redis
KEY
Node.js - A practical introduction (v2)
PDF
Openstack at NTT Feb 7, 2011
ODP
LinuxKit Swarm Nodes
PPTX
Ac cuda c_2
PDF
Elastic search
PPTX
nodester Architecture overview & roadmap
PPTX
Nodester Architecture overview & roadmap
PDF
Kubernetes Tutorial
PDF
Guillotina: The Asyncio REST Resource API
PPTX
DevStack
PDF
Introduction to Python Asyncio
PPTX
속도체크
Object Storage with Gluster
2013 PyCon SG - Building your cloud infrastructure with Python
5. configuring multiple switch with files
Blockchain Workshop - Software Freedom Day 2017
Long Tail Treasure Trove
Pusherアプリの作り方
Node.js - A Quick Tour II
StackExchange.redis
Node.js - A practical introduction (v2)
Openstack at NTT Feb 7, 2011
LinuxKit Swarm Nodes
Ac cuda c_2
Elastic search
nodester Architecture overview & roadmap
Nodester Architecture overview & roadmap
Kubernetes Tutorial
Guillotina: The Asyncio REST Resource API
DevStack
Introduction to Python Asyncio
속도체크
Ad

Similar to Techfest 2013 No RESTKit for the Weary (20)

PDF
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
KEY
RESTfull with RestKit
PDF
mobile in the cloud with diamonds. improved.
PDF
Petr Dvořák: Mobilní webové služby pohledem iPhone developera
PDF
- Webexpo 2010
PDF
Rails and iOS with RestKit
KEY
Introduction to Restkit
PPT
Connecting to a REST API in iOS
PDF
iOS Swift application architecture
PDF
GraphQL in an Age of REST
PDF
REST APIS web development for backend familiarity
PPTX
rest-api-basics.pptx
PPTX
Android and REST
PPTX
What's Parse
PDF
Xamarin Workshop Noob to Master – Week 5
PDF
PDF
RestKit Revisited
PDF
Drupal 8 and iOS - an Open Source App
PDF
Stuck in the Middle with You: Exploring the Connections Between Your App and ...
PPTX
AFNetworking
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
RESTfull with RestKit
mobile in the cloud with diamonds. improved.
Petr Dvořák: Mobilní webové služby pohledem iPhone developera
- Webexpo 2010
Rails and iOS with RestKit
Introduction to Restkit
Connecting to a REST API in iOS
iOS Swift application architecture
GraphQL in an Age of REST
REST APIS web development for backend familiarity
rest-api-basics.pptx
Android and REST
What's Parse
Xamarin Workshop Noob to Master – Week 5
RestKit Revisited
Drupal 8 and iOS - an Open Source App
Stuck in the Middle with You: Exploring the Connections Between Your App and ...
AFNetworking
Ad

More from Matt Galloway (12)

PDF
iOSDistributionOptions
PDF
You Are Here: Exploring mobile proximity awareness with iBeacon
PDF
[iOSDevelopment startAt: squareOne]; @ Tulsa School of Dev 2014
PDF
Wire Framing Presentation
PDF
Everything Staffing Folks Should Know About Mobile Development
PDF
Tulsa TechFest 2013 - StartUp Tulsa
PDF
Tulsa Dev Lunch iOS at Work
PPT
How to Hire A Developer
PDF
Tulsa Small Business Resources
PDF
Oklahoma Tweets
PDF
Love 1:46pm twitter event april 22 & 23, 2009
PDF
Tulsa Area United Way Agencies' Website Assessment & Recommendations
iOSDistributionOptions
You Are Here: Exploring mobile proximity awareness with iBeacon
[iOSDevelopment startAt: squareOne]; @ Tulsa School of Dev 2014
Wire Framing Presentation
Everything Staffing Folks Should Know About Mobile Development
Tulsa TechFest 2013 - StartUp Tulsa
Tulsa Dev Lunch iOS at Work
How to Hire A Developer
Tulsa Small Business Resources
Oklahoma Tweets
Love 1:46pm twitter event april 22 & 23, 2009
Tulsa Area United Way Agencies' Website Assessment & Recommendations

Recently uploaded (20)

PDF
giants, standing on the shoulders of - by Daniel Stenberg
DOCX
search engine optimization ppt fir known well about this
PPTX
TEXTILE technology diploma scope and career opportunities
PDF
Comparative analysis of machine learning models for fake news detection in so...
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
CloudStack 4.21: First Look Webinar slides
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
STKI Israel Market Study 2025 version august
PDF
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf
giants, standing on the shoulders of - by Daniel Stenberg
search engine optimization ppt fir known well about this
TEXTILE technology diploma scope and career opportunities
Comparative analysis of machine learning models for fake news detection in so...
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Credit Without Borders: AI and Financial Inclusion in Bangladesh
CloudStack 4.21: First Look Webinar slides
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Flame analysis and combustion estimation using large language and vision assi...
Convolutional neural network based encoder-decoder for efficient real-time ob...
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Improvisation in detection of pomegranate leaf disease using transfer learni...
sustainability-14-14877-v2.pddhzftheheeeee
OpenACC and Open Hackathons Monthly Highlights July 2025
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
STKI Israel Market Study 2025 version august
The-Future-of-Automotive-Quality-is-Here-AI-Driven-Engineering.pdf

Techfest 2013 No RESTKit for the Weary

  • 1. or the Weary No RestKit f Matt Galloway Architactile [email protected] 918-808-3072 Tuesday, January 28, 14
  • 2. Some Amazingly Cool Data from the “Cloud” ul* Web RESTF es Servic the “Cloud” REST-ish and JSONy. ul,“ of course, I mean * By “RESTF Tuesday, January 28, 14
  • 3. rvice Calls on iOS Web Se Define your URL NSString *url = @”http://somewebservice.com/objects.json”; Make the Call NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; ese delegate methods!!! Then implement all of th - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error (void)connectionDidFinishLoading:(NSURLConnection *)connection and now you have to parse the JSON in NSData into something useful... Tuesday, January 28, 14
  • 4. n is great, but... NSJSONSerializatio -(void) parseJSONIntoModel:(NSData *) jsonData { NSError *error = nil; NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&error]; if (error!=nil) { // TODO: Insert annoying JSON error handler here. } if ([json isKindOfClass:[NSArray class]]) { //TODO: Uh. I was expecting a dictionary but apparently this is an array. Writng some handling code here. } for(NSString *key in [json allKeys]) { if ([key isEqualToString:@"user"]) { NSDictionary *userDictionary = [json objectForKey:key]; NSNumber *userId = [userDictionary objectForKey:@"id"]; RKGUser *user = [[ObjectFactory sharedFactory] userForUserId:userId]; if (user==nil) { user = [[ObjectFactory sharedFactory] newUser]; user.userId=useriD; } } . . . user.name = [userDictionary objectForKey:@"name"]; user.username = [userDictionary objectForKey:@"username"]; user.phone = [userDictionary objectForKey:@"phone"]; user.email = [userDictionary objectForKey:@"email"]; Tuesday, January 28, 14
  • 5. nter RestKit E https://github.com/RestK it /RestKit/ ing and modeling ework for consum RestKit is a fram s on iOS and OS X Tful web resource RES Tuesday, January 28, 14
  • 6. [[RKObjectManager sharedManager] getObjectsAtPath:@"objects.json" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { // Call is successful. Objects are all populated. } failure:^(RKObjectRequestOperation *operation, NSError *error) { // Call failed. }]; Tuesday, January 28, 14
  • 7. RestKit is... rce & available on GitHub * Open Sou * Built on AFNetworking Beautifully multi-threaded * eamlessly with CoreData * Integrates s o works with plain objects * Als lationships, nesting, etc. * Handles re on mapping like an ORM * Based * Very configurable , POST, PATCH, etc. ndles all REST verbs - GET * Ha y actively maintained * Ver ase seeding, search, ch of other stuff - datab * A bu n XML, etc. Tuesday, January 28, 14
  • 8. ing RestKit Install I <3 CocoaPods $ cd /path/to/MyProject $ touch Podfile $ edit Podfile platform :ios, '5.0' # Or platform :osx, '10.7' pod 'RestKit', '~> 0.20.0' $ pod install $ open MyProject.xcworkspace Tuesday, January 28, 14
  • 9. Using RestKit: The W e Tuesday, January 28, 14 b Service
  • 10. Using RestKit: The Object @interface Joke : NSObject @property (nonatomic, strong) NSNumber *jokeId; @property (nonatomic, strong) NSString *text; @end @implementation Joke @end Tuesday, January 28, 14
  • 11. Using RestKit: The Setup -(void) setupRestKit { RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://api.icndb.com/"]]; objectManager.requestSerializationMIMEType=RKMIMETypeJSON; [RKObjectManager setSharedManager:objectManager]; . . . eps for CoreData, authentication, etc.) (There are a few extra st Tuesday, January 28, 14
  • 12. Using RestKit: The Mappin g RKObjectMapping *jokeMapping = [RKObjectMapping mappingForClass:[Joke class]]; [jokeMapping addAttributeMappingsFromDictionary:@{ @"id": @"joke": @"jokeId", @"text"}]; RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:jokeMapping method:RKRequestMethodGET pathPattern:@"jokes" keyPath:@"value" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; [[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor]; Tuesday, January 28, 14
  • 13. I <3 Singletons a singleton, so KObjectManager is R apping steps need the setup and m e, usually at app only be done onc launch. it and forget it. :) Se t Tuesday, January 28, 14
  • 14. Using RestKit: The Call [[RKObjectManager sharedManager] getObjectsAtPath:@"jokes" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { self.jokes = mappingResult.array; [self.tableView reloadData]; } failure:^(RKObjectRequestOperation *operation, NSError *error) { [self displayError:error]; }]; RKMappingResult has count,firstObject, array, dictionary, and set properties Tuesday, January 28, 14
  • 15. Using RestKit: The Mappin gf or POST RKObjectMapping *inverseJokeMapping = [jokeMapping inverseMapping]; RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:inverseJokeMapping objectClass:[Joke class] rootKeyPath:@"jokes" method:RKRequestMethodPOST ]; [[RKObjectManager sharedManager] addRequestDescriptor:requestDescriptor]; Tuesday, January 28, 14
  • 16. it: POSTing Using RestK Joke *aJoke=[[Joke alloc] init]; aJoke.jokeId=@9999; aJoke.text=@"Chuck Norris can find the end of a circle."; [[RKObjectManager sharedManager] postObject:aJoke path:@"jokes" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult){} failure:^(RKObjectRequestOperation *operation, NSError *error){}]; Tuesday, January 28, 14