Skip to content

Commit 642695d

Browse files
author
Josh Holtz
committed
Update README.md
1 parent b5343d2 commit 642695d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ it simply add the following line to your Podfile:
4141
#### Resource mappings
4242
`(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
4343

44+
##### Usage
45+
4446
````objc
4547

4648
@implementation ASubclassedResource
@@ -59,6 +61,34 @@ it simply add the following line to your Podfile:
5961

6062
````
6163
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.
66+
67+
````objc
68+
69+
typedef enum {
70+
JESSE,
71+
CHESTER
72+
} Character;
73+
74+
@property (nonatomic, assign) Character character;
75+
76+
- (id)initWithDictionary:(NSDictionary *)dict withLinked:(NSDictionary *)linked {
77+
self = [super initWithDictionary:dict withLinked:linked];
78+
if (self) {
79+
// Do stuff in there
80+
NSString *tatoo = [self objectForKey:@"tatoo"];
81+
if ([someKey isEqualToString:@"dude"]) {
82+
character = JESSE;
83+
} else if ([someKey isEqualToString:@"sweet"]) { {
84+
character = CHESTER
85+
}
86+
}
87+
return self;
88+
}
89+
90+
````
91+
6292
### JSONAPIResourceLinker
6393
`JSONAPIResourceLinker` is used for configuring the type of 'links' resources to 'linked' resources.
6494

0 commit comments

Comments
 (0)