2012-12-08 94 views
0

嗨,有人可以教我如何做嵌套的Restkit實體映射?我一直得到錯誤信息,而調試,下面是我的錯誤信息和代碼RestKit實體映射

[__NSSetM insertObject:atIndex:]:無法識別的選擇發送到實例0x95269d0

Core Data Family Entity

Core Data Child Entity

JSON數據

Family =(
     { 
     id = "1"; 
     parentName = "Mr John"; 
     Child =(
       { 
       parentID = "1"; 
       childName = "James"; 
       age = "18"; 

      }, 
      { 
       parentID = "1"; 
       childName = "ruby"; 
       age = "19"; 
           }, 
          { 
       parentID = "1"; 
       childName = "ella"; 
       age = "20"; 
      } 
     ); 
    } 
); 

我AppDelegate.m

RKEntityMapping *familyMapping = [RKEntityMapping mappingForEntityForName:@"Family" inManagedObjectStore:managedObjectStore]; 
debtorMapping.identificationAttributes = @[ @"id" ]; 

[familyMapping addAttributeMappingsFromDictionary:@{ 
@"id": @"accNo", 
@"parentName": @"companyName" 
}]; 


RKEntityMapping *childMapping = [RKEntityMapping mappingForEntityForName:@"Child" inManagedObjectStore:managedObjectStore]; 

childMapping.identificationAttributes = @[ @"parentID"]; 

[childMapping addAttributeMappingsFromDictionary:@{ 
@"parentID": @"parentID", 
@"childName": @"childName", 
@"age": @"age" 
}]; 


[familyMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Child" toKeyPath:@"Child" withMapping:childMapping]]; 


RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:familyMapping 
                        pathPattern:nil 
                         keyPath:@"Family" 
                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 


[objectManager addResponseDescriptor:responseDescriptor]; 

家庭NSManagedObject

@class Child; 
@interface Family : NSManagedObject 
@property (nonatomic, retain) NSString * id; 
@property (nonatomic, retain) NSString * parentName; 
@property (nonatomic, retain) NSSet *child; 
@end 
@interface Family (CoreDataGeneratedAccessors) 
- (void)addChildObject:(Child *)value; 
- (void)removeChildObject:(Child *)value; 
- (void)addChild:(NSSet *)values; 
- (void)removeChild:(NSSet *)values; 
@end 

兒童NSManageObject

@class Family; 
@interface Child : NSManagedObject 
@property (nonatomic, retain) NSString * parentID; 
@property (nonatomic, retain) NSString * childName; 
@property (nonatomic, retain) NSString * age; 
@property (nonatomic, retain) Family *family; 
@end 

回答

5

我發現我錯了。 [familyMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@「Child」toKeyPath:@「child」withMapping:childMapping]]; toKeyPath字符串應該用小寫字母來指定。 「遵循核心數據關係字符串」。