I'm new to restkit and iOS. I'm using xcode 4.2 and RestKit 0.2. I've been developing an iPhone app that communicates with some REST web services that I've created and now I'm facing a problem. A few of my web services are meant to be call more than once. The first request runs with no problem but when I try to make the call again, I get this error:
'NSInternalInconsistencyException', reason: 'Cannot add a request descriptor for the same object class as an existing request descriptor.'
I do understand what this error means but have not found a way to implement the calls that can be reused. I have a feeling I'm doing it wrong. Below is one of the functions that I'm using to call the web service:
- (void) restAddPlayer:(addPlayer*)add block:(void (^)(id))block{
// Load the object model via RestKit
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKObjectMapping *categoryRequestMapping = [RKObjectMapping requestMapping];
[categoryRequestMapping addAttributeMappingsFromDictionary:@{@"gName": @"groupName",@"pass":@"pass"}];
RKObjectMapping *reqMapping = [RKObjectMapping requestMapping];
[reqMapping addAttributeMappingsFromDictionary:@{@"plName": @"playerName"}];
[reqMapping addRelationshipMappingWithSourceKeyPath:@"groupInfo" mapping:categoryRequestMapping];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:reqMapping objectClass:[addPlayer class] rootKeyPath:nil];
[objectManager addRequestDescriptor:requestDescriptor];
objectManager.requestSerializationMIMEType = RKMIMETypeJSON;
[objectManager postObject:add path:@"addPlayer"parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSArray* statuses = [mappingResult array];
//NSLog(@"Loaded statuses: %@", statuses);
// _result = [statuses objectAtIndex:0];
block(statuses);
}
failure:^(RKObjectRequestOperation *operation, NSError *error){
NSLog(@"Hit error: %@", error);
block(nil);
}
];
}
I know I'm adding a request descriptor and when I call the function again it's trying to add another and thus the error. What I would like to know is how to handle this so I can call the web service more than once with different information in the object being post.
Thanks to all in advance.
Regards