0

我正在使用 RestKit 0.20 并在使用带有点 (.) 的规范符号时检测到一种奇怪的映射行为。如果您能解释一种简单的方法来处理从我在 IOS 上作为 NSManagedObject 实现的扁平对象到服务器端的对象关系的对象映射,我会很高兴。

映射几乎是正确的,但从我的角度来看,将 geopoint.lat 和 geopoint.lon 映射为额外字段是错误的,并且会在服务器上引发异常(无法识别的属性异常)。

RKObjectMapping:

[mapping addAttributeMappingsFromDictionary:@{
 @"geopoint.lat": @"latitude",
 @"geopoint.lon": @"longitude",
 @"countrycode": @"countryId",
 @"county": @"county",
 @"postcode": @"postalcode",
 @"city": @"city",
 @"street": @"street",
 @"housenumber": @"housenumber"
 }];

有效结果(显示为日志输出)

2013-01-29 09:29:38.856 CPlusApp[4285:907] T restkit.object_mapping:RKMappingOperation.m:514 Mapped relationship object from keyPath 'startAddress' to 'startAddress'. Value: {
city = aCity;
geopoint =     {
    lat = "48.8901234";
    lon = "8.818448999999998976";
};
"geopoint.lat" = "48.8901234";
"geopoint.lon" = "8.818448999999998976";
postcode = 91000;
street = Rennbrunnen;
}
2013-01-29 09:29:38.861 CPlusApp[4285:907] D restkit.object_mapping:RKMappingOperation.m:818 Finished mapping operation successfully...
4

1 回答 1

0

我遇到过类似的情况,我可以看到两种解决方案:

1) 为具有纬度和经度属性的地理点创建一个新类。然后geopoint在对象的类中添加为属性。从字典中删除两个映射(geopoint.lat 和 geopoint.lon)并添加从 keyPath 'geopoint' 到 'geopoint' 的关系。从那时起,您可以通过object.geopoint.lat和访问纬度和经度object.geopoint.lon

2)通过以下方式删除请求的映射:

RKEntityMapping *addressRequestMapping = [mapping inverseMapping];

[addressRequestMapping removePropertyMapping:[addressRequestMapping propertyMappingsBySourceKeyPath][@"geopoint.lat"]];
[addressRequestMapping removePropertyMapping:[addressRequestMapping propertyMappingsBySourceKeyPath][@"geopoint.lon"]];

[manager addRequestDescriptorsFromArray:@[

 [RKRequestDescriptor addressRequestMapping objectClass:[Address class] rootKeyPath:nil]

]];

选项 1 将允许您修改坐标并将数据发送到服务器,而选项 2 不允许。

于 2013-02-02T14:38:40.170 回答