Keat Choon
Keat Choon

Reputation: 131

RestKit Entity mapping

Hi can someone teach me how to do nested Restkit Entity Mapping? i keep get error message while debug, below are my error message and code

[__NSSetM insertObject:atIndex:]: unrecognized selector sent to instance 0x95269d0

Core Data Family Entity

Core Data Child Entity

Json data

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

My 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];

Family 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

Child 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

Upvotes: 0

Views: 2486

Answers (1)

Keat Choon
Keat Choon

Reputation: 131

i found out my mistake already. [familyMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Child" toKeyPath:@"child" withMapping:childMapping]]; the toKeyPath string should assign with small letter. "follow core data relationship string".

Upvotes: 5

Related Questions