我有这样的父/子类:
@interface Parent : MTLModel <MTLJSONSerializing>
- (void)someMethod;
@property a,b,c...; // from the JSON
@property NSArray *childs; // from the JSON
@end
@interface Child : MTLModel <MTLJSONSerializing>
@property d,e,f,...; // from the JSON
@property Parent *parent; // *not* in the JSON
@end
a 到 f 的所有字段都在 JSON 中,具有相同的名称(因此我的 JSONKeyPathsByPropertyKey 方法返回 nil),并且正确设置了正确的 JSONTransformer,以便 parent 中的 childs 数组包含 Child 类而不是 NSDictionary。
一切都在向前推进。
但为了方便起见,我希望在我的 Child 模型中引用回拥有它的父级的属性。所以在代码中我可以做到这一点:
[childInstance.parent someMethod]
我如何用 Mantle 做到这一点?
我希望,当父级解析孩子的 JSON 并创建 Child 类时,为其自身添加一个 ref。(使用 init 方法??)
谢谢。