Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding two request descriptors for a given class in Restkit 0.2
    primarykey
    data
    text
    <p>I need to make two different types of POST coming from the User class.</p> <pre><code>//JSON Type A { "password":"12345", "email":"test@gmail.com" } //JSON Type B { "user":{ "Password":"12345", "Email":"sample@gmail.com" } } </code></pre> <p>I've tried to make two request descriptors and adding them to my object manager however I get the error</p> <blockquote> <p>"Cannot add a request descriptor for the same object class as an existing request descriptor."</p> </blockquote> <p>My code</p> <pre><code>@interface User : NSObject @property (nonatomic, retain) NSString * userID; @property (nonatomic, retain) NSString * email; @property (nonatomic, retain) NSString * password; @property (nonatomic, retain) NSString * firstName; @property (nonatomic, retain) NSString * lastName; @end - (void)setupUserMapping:(RKObjectManager *)objectManager { // Setup user response mappings RKObjectMapping *userMapping = [RKObjectMapping mappingForClass:[User class]]; [userMapping addAttributeMappingsFromDictionary:@{ @"ID" :@"userID", @"Email" : @"email", @"Password" : @"password", @"FirstName" : @"firstName", @"LastName" : @"lastName", }]; RKResponseDescriptor *responseDescriptorAuthenticate = [RKResponseDescriptor responseDescriptorWithMapping:userMapping pathPattern:@"/Authenticate" keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]]; RKResponseDescriptor *responseDescriptorRegister = [RKResponseDescriptor responseDescriptorWithMapping:userMapping pathPattern:@"/Register" keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]]; [objectManager addResponseDescriptor:responseDescriptorRegister]; [objectManager addResponseDescriptor:responseDescriptorAuthenticate]; // Setup user request mappings RKObjectMapping* userRequestMappingForRegister = [RKObjectMapping requestMapping]; [userRequestMappingForRegister addAttributeMappingsFromDictionary:@{ @"email" : @"Email", @"password" : @"Password", @"firstName" : @"FirstName", @"lastName" : @"LastName", }]; RKRequestDescriptor *requestDescriptorForRegister = [RKRequestDescriptor requestDescriptorWithMapping:userRequestMappingForRegister objectClass:[User class] rootKeyPath:@"user"]; RKObjectMapping* userRequestMappingForAuthenticate = [RKObjectMapping requestMapping]; [userRequestMappingForAuthenticate addAttributeMappingsFromDictionary:@{ @"userID" :@"ID", @"email" : @"email", @"password": @"password" }]; RKRequestDescriptor *requestDescriptorForAuthenticate = [RKRequestDescriptor requestDescriptorWithMapping:userRequestMappingForAuthenticate objectClass:[User class] rootKeyPath:nil]; [objectManager addRequestDescriptor:requestDescriptorForRegister]; [objectManager addRequestDescriptor:requestDescriptorForAuthenticate]; } </code></pre> <p>Does anyone know how I can solve this problem without creating a separate class for these requests? </p> <p>Any help is appreciated. </p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload