Objects not loading on second request in Restkit
Posted
by
Holger Edward Wardlow Sindbæk
on Stack Overflow
See other posts from Stack Overflow
or by Holger Edward Wardlow Sindbæk
Published on 2012-11-18T19:47:23Z
Indexed on
2012/11/18
23:01 UTC
Read the original article
Hit count: 329
I'm sending off 2 requests simultaneously with Restkit and I receive a response back from both of them, but only one of the requests receives any objects. If I send them off one by one, then my objectloader receives all objects.
First request:
self.firstObjectManager = [RKObjectManager sharedManager];
[self.firstObjectManager loadObjectsAtResourcePath:[NSString stringWithFormat: @"/%@.json", subUrl] usingBlock:^(RKObjectLoader *loader){
[loader.mappingProvider setObjectMapping:designArrayMapping forKeyPath:@""];
loader.userData = @"design";
loader.delegate = self;
[loader sendAsynchronously];
}];
Second request:
self.secondObjectManager = [RKObjectManager sharedManager];
[self.secondObjectManager loadObjectsAtResourcePath:[NSString stringWithFormat: @"/%@.json", subUrl] usingBlock:^(RKObjectLoader *loader){
[loader.mappingProvider setObjectMapping:designerMapping forKeyPath:@""];
loader.userData = @"designer";
loader.delegate = self;
[loader sendAsynchronously];
}];
My objecloader:
-(void)objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects
{
//NSLog(@"This happened: %@", objectLoader.userData);
if (objectLoader.userData == @"design") {
NSLog(@"Design happened: %i", objects.count);
}else if(objectLoader.userData == @"designer"){
NSLog(@"designer: %@", [objects objectAtIndex:0]);
}
}
My response:
2012-11-18 14:36:19.607 RestKitTest5[14220:c07] Started loading of request: designer
2012-11-18 14:36:22.575 RestKitTest5[14220:c07] I restkit.network:RKRequest.m:680:-[RKRequest updateInternalCacheDate] Updating cache date for request <RKObjectLoader: 0x95c3160> to 2012-11-18 19:36:22 +0000
2012-11-18 14:36:22.576 RestKitTest5[14220:c07] response code: 200
2012-11-18 14:36:22.584 RestKitTest5[14220:c07] Design happened: 0
2012-11-18 14:36:22.603 RestKitTest5[14220:c07] I restkit.network:RKRequest.m:680:-[RKRequest updateInternalCacheDate] Updating cache date for request <RKObjectLoader: 0xa589b50> to 2012-11-18 19:36:22 +0000
2012-11-18 14:36:22.605 RestKitTest5[14220:c07] response code: 200
2012-11-18 14:36:22.606 RestKitTest5[14220:c07] designer: <DesignerData: 0xa269fc0>
Update: Setting my base url
RKURL *baseURL = [RKURL URLWithBaseURLString:@"http://iphone.meer.li"];
[RKObjectManager setSharedManager:[RKObjectManager managerWithBaseURL:baseURL]];
Solution
Problem was that I used the shared manager for both object managers, so I ended up doing:
RKURL *baseURL = [RKURL URLWithBaseURLString:@"http://iphone.meer.li"];
RKObjectManager *myObjectManager = [[RKObjectManager alloc] initWithBaseURL:baseURL];
self.firstObjectManager = myObjectManager;
and:
RKURL *baseURL = [RKURL URLWithBaseURLString:@"http://iphone.meer.li"];
RKObjectManager *myObjectManager = [[RKObjectManager alloc] initWithBaseURL:baseURL];
self.secondObjectManager = myObjectManager;
© Stack Overflow or respective owner