可以为相同的 pathPattern 添加几个响应映射吗?
我有下一个情况:
获取请求: RKEntityMapping * restDayMapping = [RestDay entityMapping]; RKResponseDescriptor * restDayDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:restDayMapping pathPattern:@"program/restdays" keyPath:@"rest_days" statusCodes:statusCodes]; [经理 addResponseDescriptor:restDayDescriptor]; 提出要求: RKObjectMapping * restDayPutMapping = [RKObjectMapping requestMapping]; [restDayPutMapping addAttributeMappingsFromDictionary:@{@"dayNumber" : @"restDays.dayNumber"}]; RKRequestDescriptor * restDayPutDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:[restDayPutMapping inverseMapping] objectClass:[UserProgram class] rootKeyPath:@"rest_days"]; [经理 addRequestDescriptor:restDayPutDescriptor];
所以两个映射都通过相同的路径模式发送:@“program/restdays”但是对于第一个 GET 请求服务器端返回 json:
{"rest_days":[{"dayNumber":1},{"dayNumber":4},{"dayNumber":2}]}。
对于第二个 PUT 请求,json:
{“成功”:“真”}
我必须如何配置我的 restkit 映射?谢谢你。
编辑:升级 restkit 库并发现了很棒的功能,方法被贬低了:
+ (instancetype)responseDescriptorWithMapping:(RKMapping *)mapping pathPattern:(NSString *)pathPattern keyPath:(NSString *)keyPath statusCodes:(NSIndexSet *)statusCodes
并添加了新的:
+ (instancetype)responseDescriptorWithMapping:(RKMapping *)mapping 方法:(RKRequestMethod)方法 pathPattern:(NSString *)pathPattern keyPath:(NSString *)keyPath statusCodes:(NSIndexSet *)statusCodes
所以现在我可以为不同的请求方法设置不同的映射。感谢大家的帮助。