問題なく通常の JSON オブジェクトをモデル化していますが、国際化のために、属性が文字列またはキーと値のペアの辞書である可能性がある次のシナリオをモデル化したいと考えています。
"objects": [{"title": "non internatinalizaed title", ...},
{"title": {"en": "english string", "es": "spanish string"}, ...},
....]
サーバーが単一の文字列を送信するのか複数の文字列を送信するのかわからないので、次のようなモデル オブジェクトを作成することを考えていました。
@interface I18NString : Object
@property (copy) NSString *forced; // Set when there is no i18n
@property (copy) NSDictionary *strings; // Set with i18n.
- (NSString*)stringValue; // Returns forced or one of strings
C の構造体共用体と同様に、nil でないかどうかに応じてstrings
、メソッド内でいずれかのプロパティを選択しますstringValue
。Restkit wiki のDynamic object mappingセクションを読みましたが、それを使用してこの問題を解決する方法がわかりません。