I wanna ask something in here. I've mapping the the object and add it to RKResponseDescriptor and it works, but there's a problem here. when the data from JSON is different, it doesn't mapping to the object that already created I just realize that it doesn't mapping well.
// Setup our object mappings
RKObjectMapping *applicationMapping = [RKObjectMapping mappingForClass:[ApplicationSettings class]];
[applicationMapping addAttributeMappingsFromDictionary:@{
@"filterRead" : @"filterRead",
@"filterUserComments" : @"filterUserComments"
}];
RKObjectMapping *categoryMapping = [RKObjectMapping mappingForClass:[Category class]];
[categoryMapping addAttributeMappingsFromDictionary:@{
@"id" : @"categoryID",
@"title" : @"title",
@"slug" : @"slug"
}];
RKObjectMapping *commentMapping = [RKObjectMapping mappingForClass:[Comment class]];
commentMapping.forceCollectionMapping = YES;
[commentMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"comments"];
[categoryMapping addAttributeMappingsFromDictionary:@{
@"(coments).id" : @"commentID",
@"(comments).date" : @"createdDate",
@"(comments).content" : @"comment"
}];
RKObjectMapping *errorMapping = [RKObjectMapping mappingForClass:[Error class]];
[errorMapping addAttributeMappingsFromDictionary:@{
@"error" : @"error",
@"status" : @"status"
}];
RKObjectMapping *postMapping = [RKObjectMapping mappingForClass:[Post class]];
postMapping.forceCollectionMapping = YES;
[postMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"posts"];
[errorMapping addAttributeMappingsFromDictionary:@{
@"id" : @"postID",
@"title" : @"title",
@"content" : @"content",
@"date" : @"createdDate",
@"modified" : @"modifiedDate"
}];
RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[User class]];
[userMapping addAttributeMappingsFromDictionary:@{
@"nonce" : @"nonce",
@"cookie" : @"cookie",
@"username" : @"userName",
@"email" : @"email"
}];
// Register our mappings with the provider using a response descriptor
RKResponseDescriptor *userResponse = [RKResponseDescriptor responseDescriptorWithMapping:userMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *applicationResponse = [RKResponseDescriptor responseDescriptorWithMapping:applicationMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *categoryResponse = [RKResponseDescriptor responseDescriptorWithMapping:categoryMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *commentResponse = [RKResponseDescriptor responseDescriptorWithMapping:commentMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *errorResponse = [RKResponseDescriptor responseDescriptorWithMapping:errorMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
RKResponseDescriptor *postResponse = [RKResponseDescriptor responseDescriptorWithMapping:postMapping
pathPattern:nil
keyPath:nil
statusCodes:(RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful))];
[objectManager addResponseDescriptorsFromArray:
@[
applicationResponse,
categoryResponse,
commentResponse,
userResponse,
postResponse,
errorResponse
]] ;
edit number 1:
[objectManager addResponseDescriptorsFromArray:
@[
applicationResponse,
categoryResponse,
commentResponse,
errorResponse,
postResponse,
userResponse
]] ;
for this one, the JSON data for user can be mapped but not for the other. What I mean is can we mapped the object something like this? because I was changed the order of the responseDescriptors and it just mapped the object at the bottom.
Sorry for my bad english before