You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A library for loading data from a [JSON API](http://jsonapi.org) datasource. Parses JSON API data into models with support for auto-linking of resources and custom model classes.
6
7
7
8
### Updates
8
9
9
10
Version | Changes
10
11
--- | ---
12
+
**0.1.3** | Added `NSCopying` and `NSCoded` to `JSONAPIResource`; Added `JSONAPIResourceFormatter` to format values before getting mapped - [more info](#formatter)
11
13
**0.1.2** | `JSONAPIResource` IDs can either be numbers or strings (thanks [danylhebreux](https://github.com/danylhebreux)); `JSONAPIResource` subclass can have mappings defined to set JSON values into properties automatically - [more info](#resource-mappings)
12
14
**0.1.1** | Fixed linked resources with links so they actually link to other linked resources
13
15
**0.1.0** | Initial release
@@ -41,18 +43,34 @@ it simply add the following line to your Podfile:
41
43
#### Resource mappings
42
44
`(NSDictionary*)mapKeysToProperties` can be overwritten to define a dictionary mapping of JSON keys to map into properties of a subclassed JSONAPIResource. Use a "links." prefix on the JSON key to map a linked JSONAPIResource model or array of JSONAPIResource models
43
45
46
+
#### Formatter
47
+
`JSONAPIResourceFormatter` is used to format values before getting mapped from `mapKeysToProperties`.
// Maps values in JSON key 'first_name' to 'firstName' property
68
+
// Maps values in JSON key 'date' to 'date' property using the 'Date' formatter
52
69
// Maps linked resource in JSON key 'author' to 'author' property
53
70
// Maps linked resource in JSON key 'comments' to 'comments' property
54
71
return @{
55
72
@"first_name" : @"firstName",
73
+
@"date" : @"Date:date",
56
74
@"links.author" : @"author",
57
75
@"links.comments" : @"comments"
58
76
};
@@ -61,31 +79,24 @@ it simply add the following line to your Podfile:
61
79
62
80
````
63
81
64
-
##### Map values outside of `mapKeysToProperties` method
65
-
If you need to map values that are a little odd, like mapping to enums or performing some sort of formatting before setting a property, you can override the `initWithDictionary` method and assign properties in there.
82
+
##### Using `JSONAPIResourceFormatter` to format values
83
+
Below is an example to register a "Date" function to format a date in a NSString object to an NSDate object before its mapped to the JSONAPIResource instance.
66
84
67
85
````objc
68
86
69
-
typedef enum {
70
-
JESSE,
71
-
CHESTER
72
-
} Character;
73
-
74
-
@property (nonatomic, assign) Character character;
0 commit comments