Skip to content

Commit cdce76a

Browse files
committed
Add convenience setter for property and json label to resource descriptor.
1 parent 8a675a8 commit cdce76a

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

Classes/JSONAPIResourceDescriptor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@
9797
*/
9898
- (void)addProperty:(NSString*)name;
9999

100+
/**
101+
* Add a simple property with custom json name.
102+
*
103+
* @param name The name of the property in the class.
104+
* @param jsonName The label of the property in JSON.
105+
*/
106+
- (void)addProperty:(NSString*)name withJsonName:(NSString *)json;
107+
100108
/**
101109
* Add a simple property with custom transform object.
102110
*

Classes/JSONAPIResourceDescriptor.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ - (void)addProperty:(NSString*)name {
5353
[self addProperty:name withDescription:[[JSONAPIPropertyDescriptor alloc] initWithJsonName:name]];
5454
}
5555

56+
- (void)addProperty:(NSString*)name withJsonName:(NSString *)json
57+
{
58+
[self addProperty:name withDescription:[[JSONAPIPropertyDescriptor alloc] initWithJsonName:json]];
59+
}
60+
5661
- (void)addProperty:(NSString*)name withDescription:(JSONAPIPropertyDescriptor*)description {
5762
[[self properties] setValue:description forKey:name];
5863
}

Project/JSONAPI/CommentResource.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ + (JSONAPIResourceDescriptor*)descriptor {
2525

2626
[__descriptor setIdProperty:@"ID"];
2727

28-
[__descriptor addProperty:@"text" withDescription:[[JSONAPIPropertyDescriptor alloc] initWithJsonName:@"body"]];
28+
[__descriptor addProperty:@"text" withJsonName:@"body"];
2929

3030
[__descriptor hasOne:[PeopleResource class] withName:@"author"];
3131
});

Project/JSONAPI/PeopleResource.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ + (JSONAPIResourceDescriptor*)descriptor {
2323
[__descriptor setIdProperty:@"ID"];
2424

2525
[__descriptor addProperty:@"firstName" withDescription:[[JSONAPIPropertyDescriptor alloc] initWithJsonName:@"first-name"]];
26-
[__descriptor addProperty:@"lastName" withDescription:[[JSONAPIPropertyDescriptor alloc] initWithJsonName:@"last-name"]];
26+
[__descriptor addProperty:@"lastName" withJsonName:@"last-name"];
2727
[__descriptor addProperty:@"twitter"];
2828
});
2929

0 commit comments

Comments
 (0)