1

私は次の構造をマッピングしようとしています:

Plan.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の例からのものです。しかし、私はまだこの応答を得ました:計画のために

<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>)"
)

エラーはスローされず、間違ったデータだけがスローされます。あなたはそれをどうするか考えていますか?

ありがとうトーマス

4

0 に答える 0