私はこのような親/子クラスを持っています:
@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 が正しく設定されているため、親の子配列には NSDictionary ではなく子クラスが含まれます。
すべてが前向きに働きます。
しかし、便宜上、それを所有する親を参照するChildモデルのプロパティが必要です。そのため、コードで次のことができます。
[childInstance.parent someMethod]
マントルでそれを行うにはどうすればよいですか??
親が子の JSON を解析して Child クラスを作成しているときに、自分自身に ref を追加したい。(initメソッドで??)
ありがとう。