Search code examples
objective-crestkit

Cannot add a route with the same class and method as an existing route


I am trying to addRoutes but getting "Cannot add a route with the same class and method as an existing route."

I have a class Thing that has the same route method for Post, but with a different method of course. When I try to run my app I get the above error. Is there a way to setup the route with a generic method?

[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
                                                    pathPattern:@"v1/things/update_location.json.json" method:RKRequestMethodPOST]];

[objectManager.router.routeSet addRoute:[RKRoute routeWithClass:[Thing class]
                                                    pathPattern:@"v1/things.json" method:RKRequestMethodPOST]];

The above is a duplicate according to Restkit, as it using the same class "Thing" and because the Method is the same? What gives?


Solution

  • A router is used to build a request when given an object (an instance of Thing in this case). For this to work there can only be a single option of what to do when you ask RestKit to post an object. Any other routes need to be described in terms of named routes or relationship routes to maintain the uniqueness of the routing set.

    You can check the documentation here and it describes all 3 of the methods for defining routers in the 'Route Generation' section (you're currently only using method 2). Most likely you want to define some named routes which describe the differences between what you are trying to achieve with each upload.