22. Our Book Model could
have a JSON representation
{
...
"artistName": "Neil Gaiman, Sam Keith & Mike Dringenberg",
"description": "<p>NEW YORK TIMES bestselling author...",
"genres": ["Graphic Novels", "Books", "Comics & Graphic Novels"],
"releaseDate": "2012-08-21T07:00:00Z",
"trackId": 554016043,
"trackName": "The Sandman, Vol. 1: Preludes & Nocturnes (New Edition)",
"artworkUrl100": "http://a4.mzstatic.com/us/r30/Publication/...",
...
}
23. Our Book Model could
have a JSON representation
{
...
"artistName": "Neil Gaiman, Sam Keith & Mike Dringenberg",
"description": "<p>NEW YORK TIMES bestselling author...",
"genres": ["Graphic Novels", "Books", "Comics & Graphic Novels"],
"releaseDate": "2012-08-21T07:00:00Z",
"trackId": 554016043,
"trackName": "The Sandman, Vol. 1: Preludes & Nocturnes (New Edition)",
"artworkUrl100": "http://a4.mzstatic.com/us/r30/Publication/...",
...
}
This is how iTunes represents media (including books)
24. Our Book Model could
have a JSON representation
{
...
"artistName": "Neil Gaiman, Sam Keith & Mike Dringenberg",
"description": "<p>NEW YORK TIMES bestselling author...",
"genres": ["Graphic Novels", "Books", "Comics & Graphic Novels"],
"releaseDate": "2012-08-21T07:00:00Z",
"trackId": 554016043,
"trackName": "The Sandman, Vol. 1: Preludes & Nocturnes (New Edition)",
"artworkUrl100": "http://a4.mzstatic.com/us/r30/Publication/...",
...
}
This is how iTunes represents media (including books)
See http://www.apple.com/itunes/affiliates/resources/
documentation/itunes-store-web-service-search-api.html
29. + (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"author" : @"artistName",
@"overview" : @"description",
@"identifier" : @"trackId",
@"title" : @"trackName",
@"coverURL" : @"artworkUrl100"
};
}
Only properties with a corresponding ivar
30. + (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"author" : @"artistName",
@"overview" : @"description",
@"identifier" : @"trackId",
@"title" : @"trackName",
@"coverURL" : @"artworkUrl100"
};
}
Only properties with a corresponding ivar
Property keys not present in the dictionary are
assumed to match the JSON
53. MTLManagedObjectSerializing protocol
@interface TGRBook : MTLModel <MTLManagedObjectSerializing>
Specify the entity name
Specify how to map properties to managed
object attributes
Specify how to convert a managed object
attribute value to a property key
56. A delightful iOS and OS X networking framework
Built on top of Foundation technologies
Easy to use block-based API
Amazing community of developers
Used by some of the most popular apps on iOS
and OSX
https://github.com/AFNetworking/AFNetworking
62. NSArray *results = JSONResponse[@"results"];
NSValueTransformer *transformer;
transformer = [NSValueTransformer mtl_JSONArrayTransformerWithModelClass:TGRBook.class];
NSArray *books = [transformer transformedValue:results];
Mapping can potentially take time
63. NSArray *results = JSONResponse[@"results"];
NSValueTransformer *transformer;
transformer = [NSValueTransformer mtl_JSONArrayTransformerWithModelClass:TGRBook.class];
NSArray *books = [transformer transformedValue:results];
Mapping can potentially take time
It should be done in a background queue
64. NSArray *results = JSONResponse[@"results"];
NSValueTransformer *transformer;
transformer = [NSValueTransformer mtl_JSONArrayTransformerWithModelClass:TGRBook.class];
NSArray *books = [transformer transformedValue:results];
Mapping can potentially take time
It should be done in a background queue
Boilerplate code again!
65. Overcoat
The perfect accessory for Mantle
Makes it dead simple to use Mantle model
objects with a RESTful client
AFNetworking extension
https://github.com/gonzalezreal/Overcoat
71. Overcoat
Server API requests are defined by
OVCQuery objects.
HTTP method, path, parameters, model
class, multipart data, etc.
Maps JSON into model(s)
In a private background queue