我正在尝试映射以下结构:
计划.json:
{
"id" : "1",
"floors" : [
{
"floor" : "1",
"constrains" :
{
"southWest":
{
"latitude": 50.076534 ,
"longitude": 14.417152
},
"northEast":
{
"latitude": 50.077194,
"longitude": 14.418526
}
}
}
]
}
对于这个结构:
@interface Plan : NSManagedObject
@property (nonatomic, retain) NSNumber * id;
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) Building *building;
@property (nonatomic, retain) NSSet *floors;
@end
@interface Floor : NSManagedObject
@property (nonatomic, retain) NSNumber * floorId;
@property (nonatomic, retain) NSNumber * planId;
@property (nonatomic, retain) NSNumber * southWestLatitude;
@property (nonatomic, retain) NSNumber * southWestLongitude;
@property (nonatomic, retain) NSNumber * northEastLatitude;
@property (nonatomic, retain) NSNumber * northEastLongitude;
@property (nonatomic, retain) Plan *plan;
@end
映射:
RKEntityMapping *floorMapping = [RKEntityMapping mappingForEntityForName:@"Floor" inManagedObjectStore:managedObjectStore];
floorMapping.identificationAttributes = @[ @"floorId" ];
[floorMapping addAttributeMappingsFromDictionary:@{
@"floor": @"floorId",
@"constraints.southWest.latitude": @"southWestLatitude",
@"constraints.southWest.longitude": @"southWestLongitude",
@"constraints.northEast.latitude": @"northEastLatitude",
@"constraints.northEast.longitude": @"northEastLongitude"
}];
RKEntityMapping *planMapping = [RKEntityMapping mappingForEntityForName:@"Plan" inManagedObjectStore:managedObjectStore];
planMapping.identificationAttributes = @[ @"id" ];
[planMapping addAttributeMappingsFromDictionary:@{
@"id": @"id"}];
[planMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"floors" toKeyPath:@"floors" withMapping:floorMapping]];
我认为我做的一切都是正确的,它实际上来自 TwitterCoreData 示例。但我还是得到了这样的回应:For plan
<Plan: 0x7385ca0> (entity: Plan; id: 0x736fdf0 <x-coredata://C74D92C0-FF0D-49F4-807B-F8B431733B8A/Plan/p1> ; data: {
floors = "<relationship fault: 0x7386ac0 'floors'>";
id = 1;
})
而对于地板
2013-02-07 14:39:55.184 CVUT Navigator[18061:c07] (
"<Floor: 0x9353130> (entity: Floor; id: 0x933d670 <x-coredata://C74D92C0-FF0D-49F4-807B-F8B431733B8A/Floor/p1> ; data: <fault>)"
)
没有抛出错误,只是错误的数据。你知道该怎么做吗?
谢谢托马斯