Search code examples
iosrestkit

Processing RestKit Response to get params not in entity


I have an entity Comments. When I perform a rest operation, i get a response which has fields such as { "status": "succeed" } I want to process these fields to know if the operation was successful or not but I dont want to add status to comment class because it doesnt belogn there.

RKObjectManager *sharedRKObjectManager = [RKObjectManager sharedManager];
RKManagedObjectStore *managedObjectStore = [sharedRKObjectManager managedObjectStore];
// Create a mapping for the comment entity
RKEntityMapping *responseMapping = [RKEntityMapping mappingForEntityForName:ENTITY_COMMENT inManagedObjectStore:managedObjectStore];
[responseMapping addAttributeMappingsFromDictionary:@{
                                                      @"comment_id":    @"commentId"
                                                      }];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:responseMapping
                                                                                        method:RKRequestMethodAny
                                                                                   pathPattern:COMMENT
                                                                                       keyPath:nil
                                                                                   statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

Whats the best way to do this?


Solution

  • Just use a plain RKObjectMapping to a custom class or an NSDictionary and with the single status key. Then you should get a simple single item in the mapping result.