File tree Expand file tree Collapse file tree 5 files changed +43
-0
lines changed Expand file tree Collapse file tree 5 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 135
135
*/
136
136
- (void )setID : (id )identifier ;
137
137
138
+ /* *
139
+ * Get the meta for a resource instance. Optional for resources that come
140
+ * from persistance storage (i.e. the server).
141
+ *
142
+ * In general, this should be implemented by a @property ID in the realized class. The
143
+ * @property declaration will automatically synthesize the get/set members declared in this
144
+ * protocol. The property storage is an implementation detail, which is why the protocol does
145
+ * not use a @property declaration.
146
+ *
147
+ * @return The meta for a resource instance.
148
+ */
149
+ - (NSDictionary *)meta ;
150
+
151
+ /* *
152
+ * Set the meta for a resource instance. Optional for resources that come
153
+ * from persistance storage (i.e. the server).
154
+ *
155
+ * In general, this should be implemented by a @property ID in the realized class. The
156
+ * @property declaration will automatically synthesize the get/set members declared in this
157
+ * protocol. The property storage is an implementation detail, which is why the protocol does
158
+ * not use a @property declaration.
159
+ *
160
+ * @param meta The meta for a resource instance.
161
+ */
162
+ - (void )setMeta : (NSDictionary *)meta ;
138
163
139
164
@end
Original file line number Diff line number Diff line change 43
43
*/
44
44
@property (strong , atomic ) id ID;
45
45
46
+ /* *
47
+ * Meta for a resource instance. Optional for resources that come
48
+ * from persistance storage (i.e. the server).
49
+ */
50
+ @property (strong , atomic ) NSDictionary *meta;
51
+
46
52
@end
Original file line number Diff line number Diff line change @@ -181,6 +181,7 @@ + (void)set:(NSObject <JSONAPIResource> *)resource withDictionary:dictionary {
181
181
NSDictionary *relationships = [dictionary objectForKey: @" relationships" ];
182
182
NSDictionary *attributes = [dictionary objectForKey: @" attributes" ];
183
183
NSDictionary *links = [dictionary objectForKey: @" links" ];
184
+ NSDictionary *meta = [dictionary objectForKey: @" meta" ];
184
185
185
186
id ID = [dictionary objectForKey: @" id" ];
186
187
NSFormatter *format = [descriptor idFormatter ];
@@ -197,6 +198,10 @@ + (void)set:(NSObject <JSONAPIResource> *)resource withDictionary:dictionary {
197
198
NSString *selfLink = links[@" self" ];
198
199
[resource setValue: selfLink forKey: descriptor.selfLinkProperty];
199
200
}
201
+
202
+ if ([resource respondsToSelector: @selector (setMeta: )]) {
203
+ [resource setMeta: meta];
204
+ }
200
205
201
206
// Loops through all keys to map to properties
202
207
NSDictionary *properties = [descriptor properties ];
Original file line number Diff line number Diff line change @@ -64,6 +64,10 @@ - (void)testDataArticles {
64
64
XCTAssertEqual (jsonAPI.resources .count , 1 , @" Resources should contain 1 resource" );
65
65
66
66
ArticleResource *article = jsonAPI.resource ;
67
+
68
+ XCTAssertNotNil (article.meta , @" Meta should not be nil" );
69
+ XCTAssertEqualObjects (article.meta [@" hehe" ], @" hoho" , @" Meta's 'hehe' should equal 'hoho'" );
70
+
67
71
XCTAssert ([article isKindOfClass: [ArticleResource class ]], @" Article should be a ArticleResource" );
68
72
XCTAssertEqualObjects (article.ID , @" 1" , @" Article id should be 1" );
69
73
XCTAssertTrue ([article.selfLink isEqualToString: @" http://example.com/articles/1" ], @" Article selfLink should be 'http://example.com/articles/1'" );
Original file line number Diff line number Diff line change 10
10
"data" : [{
11
11
"type" : " articles" ,
12
12
"id" : " 1" ,
13
+ "meta" : {
14
+ "hehe" : " hoho"
15
+ },
13
16
"attributes" : {
14
17
"title" : " JSON API paints my bikeshed!" ,
15
18
"versions" : [
You can’t perform that action at this time.
0 commit comments