JSON
以下のような回答があります。
{
response : {
data : {
subjects : [
{
},
{
}
]
}
}
}
そして、私は次のように NSManagedObject を持っています:
@interface Department : NSManagedObject
@property (nonatomic, retain) NSNumber * id;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSSet *subjects;
@end
Department
テーブルに id = 1 で name = "Physics"の部門レコードがあります。subjects
この既存の部門を、応答の JSON データから取得したもので変更したいと考えています。件名フィールドのみが更新され、残りは同じままにする必要があります。このための RestKit 0.20 マッピング コードを教えてください。
アップデート
これは私が実行したマッピングです:
NSDictionary *subMappingDict = @{
@"id": @"id",
@"sub_name": @"name"
};
RKEntityMapping *subMapping = [RKEntityMapping mappingForEntityForName:@"Subject" inManagedObjectStore:managedObjectStore];
[subMapping addAttributeMappingsFromDictionary:subMappingDict];
subMapping.identificationAttributes = @[@"id"];
RKEntityMapping *deptMapping = [RKEntityMapping mappingForEntityForName:@"Department" inManagedObjectStore:managedObjectStore];
[deptMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"subjects" toKeyPath:@"subjects" withMapping:subMapping]];
RKEntityMapping *collegeMapping = [RKEntityMapping mappingForEntityForName:@"College" inManagedObjectStore:managedObjectStore];
[collegeMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"data" toKeyPath:@"department" withMapping:deptMapping]];
NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:collegeMapping pathPattern:nil keyPath:@"response" statusCodes:statusCodes];
既存のCollege
レコードを持つ既存のレコードがありDepartment
ます。subjects
ここでは、マッピングのみによって部門のフィールドを更新したいと考えています。