RestKitAPI
を使用して CoreData オブジェクトへの応答のマッピングを実現する方法を理解しようとしています。はJSOG標準を使用します。次に例を示します。API
[
{
"@id": "1",
"name": "Sally",
"friend": {
"@id": "2",
"name": "Bob",
"friend": {
"@id": "3",
"name": "Fred",
"friend": { "@ref": "1" }
}
}
},
{ "@ref": "2" },
{ "@ref": "3" }
]
RKEntityMapping
そのような のを作成するにはどうすればよいJSON
ですか? 単純な属性のマッピングは簡単です。問題は@ref
、トップレベルのユーザー オブジェクトに@ref
のみが含まれている場合でも、 と連携するようにここで関係をセットアップする方法です。
RKEntityMapping *userMapping = [RKEntityMapping mappingForEntityForName:@"Question"
inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore];
[userMapping addAttributeMappingsFromDictionary:@
{
@"@id" : @"identifier",
@"name" : @"name"
}];
[userMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"friend"
toKeyPath:@"friend"
withMapping:userMapping]];
私の推測では、以下のコードを使用し@ref
てオブジェクトの内部を処理できます。
[userMapping addConnectionForRelationship:@"friend" connectedBy:@{@"@ref": @"@id"}];
しかし、それは正しいですか?
- 完全なオブジェクトまたは既に提供されているオブジェクトへの参照 (を介して
@ref
) を実際の Core Data オブジェクトにマップするにはどうすればよいですか? User
JSON の上位要素 (オブジェクトのリスト) を実際のUser
エンティティのリストにマップするにはどうすればよいですか?