Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestKit: distinguish multiple requests in didLoadResponse:

I'd like to use RestKit and handle several different requests in the same class, i.e. in the didLoadResponse: method. How can I distinguish between the different requests? How do I know which request is finished?

I'm doing the request via

RKClient *client = [RKClient sharedClient];
[client get:@"/....", method] delegate:self];

Then, in the delegate-method

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
    if (???) // request which gets XY returned
        ...
    else if (???) // request which gets YZ returned
        ...
}

is that possible?

like image 203
swalkner Avatar asked Dec 05 '11 15:12

swalkner


1 Answers

Sure, the RKClient get: method returns a RKRequest object. Just set a userData to the request and retrieve it later in the delegate.

RKClient *client = [RKClient sharedClient];
RKRequest *request = [client get:@"/....", method] delegate:self];
[request setUserData:@"FirstRequest"];

and check it later in the delegate

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response {
    id userData = [request userData];
    if ([userData isEqual:@"FirstRequest"]) // request which gets XY returned
        ...
    else if (...) // request which gets YZ returned
        ...
}
like image 85
mja Avatar answered Dec 09 '22 16:12

mja