我将核心数据中的对象保存为以下格式。
{
"propertyId": 1,
"name": "some_name_1",
"userName": "some_email_1"
},
{
"propertyId": 1,
"name": "some_name_2",
"userName": "some_email_2"
},
{
"propertyId": 2,
"name": "some_name_3",
"userName": "some_email_3"
},
{
"propertyId": 2,
"name": "some_name_4",
"userName": "some_email_4"
},
{
"propertyId": 3,
"name": "some_name_5",
"userName": "some_email_5"
},
{
"propertyId": 3,
"name": "some_name6_",
"userName": "some_email_6"
}
现在,问题是只有同一propertyId组中的最后一个对象才会保存在Core Data中。
这是我从之前的开发人员那里得到的代码。映射用于存储数据。
RKEntityMapping *rkEntityMapping = [RKEntityMapping mappingForEntityForName:@"PropertyAssignee" inManagedObjectStore:self.managedObjectStore];
rkEntityMapping.identificationAttributes = @[@"propertyId"];
[rkEntityMapping addAttributeMappingsFromDictionary:@{
@"propertyId": @"propertyId",
@"name": @"name",
@"userName": @"userName"}];
[rkEntityMapping addConnectionForRelationship:@"property" connectedBy:@{@"propertyId": @"objId"}];
RKObjectMapping *syncMapping = [RKObjectMapping mappingForClass:[NSMutableDictionary class]];
[syncMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"propertyAssgineeResponse" toKeyPath:@"propertyAssgineeResponse" withMapping:propertAssigneeMapping]];
RKResponseDescriptor *responseDescriptorProperties = [RKResponseDescriptor responseDescriptorWithMapping:syncMapping method:RKRequestMethodAny pathPattern:@"/api/sync" keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]];
[self.objectManager addResponseDescriptor:responseDescriptorProperties];
我不知道为什么会发生这种情况。