【发布时间】:2014-01-14 15:28:10
【问题描述】:
过去我为每个 RKResponseDescriptor 以及每个 RKObjectManager get/post/patch/delete 方法指定了路径参数。这可行,但似乎 RKRouter 是更好、更模块化的方式。
我无法设置包含嵌套变量的动态路由。例如:
添加路线
RKRoute *locationsRoute = [RKRoute routeWithClass:[Location class] pathPattern:@"users/:userID/locations/:locationID" method:RKRequestMethodAny];
[[RKObjectManager sharedManager].router.routeSet addRoutes:@[locationsRoute]];
设置响应描述符
RKResponseDescriptor *locationResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:locationResponseMapping
method:RKRequestMethodAny
pathPattern:nil
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
调用对象管理器
[[RKObjectManager sharedManager] getObject:[Location class] path:nil parameters:nil success:nil failure:nil];
在使用路由器之前,我会在对象管理器调用路径中包含用户 ID。 (例如:path:[NSString stringWithFormat:@"users/%@/locations/%@", [self getCurrentUser].userID, location.locationID])。但是,在使用路由器时,我似乎无法弄清楚如何指定它。 这样做的正确方法是什么?我希望不必将用户 ID 硬编码到路由路径中。
重要的是要注意,我的所有映射都已正确设置,在尝试实施路线之前一切都完美无缺。任何帮助表示赞赏!
【问题讨论】:
标签: ios objective-c restkit restkit-0.20 rkobjectmapping