
//JsON Type A{ "password":"12345","email":"test@gmail.com"}//JsON Type B{ "user":{ "Password":"12345","Email":"sample@gmail.com" }} 我试图制作两个请求描述符并将其添加到我的对象管理器,但是我收到错误
“Cannot add a request descriptor for the same object class as an
existing request descriptor.”
我的代码
@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];} 有没有人知道如何解决这个问题,而不需要为这些请求创建一个单独的类?
任何帮助是赞赏.
谢谢.
解决方法 您可以使用动态映射来切换序列化行为.如果这是一个很常见的问题,我们可以想象地将路径匹配添加到请求描述符中.我只是没有这么多的要求.有一个例子说明如何在单元测试中使用带有请求的动态映射:https://github.com/RestKit/RestKit/blob/master/Tests/Logic/ObjectMapping/RKObjectParameterizationTest.m#L495-L534
总结以上是内存溢出为你收集整理的ios – 在Restkit 0.2中为给定的类添加两个请求描述符全部内容,希望文章能够帮你解决ios – 在Restkit 0.2中为给定的类添加两个请求描述符所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)