diff --git a/Code/ObjectMapping/RKObjectLoader.m b/Code/ObjectMapping/RKObjectLoader.m index b4b3ee1e..8d4908a3 100644 --- a/Code/ObjectMapping/RKObjectLoader.m +++ b/Code/ObjectMapping/RKObjectLoader.m @@ -145,7 +145,7 @@ - (void)processLoadModelsInBackground:(RKResponse *)response { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - RKManagedObjectStore* objectStore = [[RKObjectManager globalManager] objectStore]; // TODO: Should probably relax singleton... + RKManagedObjectStore* objectStore = self.managedObjectStore; // If the request was sent through a model, we map the results back into that object // TODO: Note that this assumption may not work in all cases, other approaches? @@ -174,10 +174,10 @@ results = [NSArray arrayWithObjects:result, nil]; } - if (self.managedObjectStore && [self.managedObjectStore managedObjectCache]) { + if (objectStore && [objectStore managedObjectCache]) { if ([self.URL isKindOfClass:[RKURL class]]) { RKURL* rkURL = (RKURL*)self.URL; - NSArray* fetchRequests = [[self.managedObjectStore managedObjectCache] fetchRequestsForResourcePath:rkURL.resourcePath]; + NSArray* fetchRequests = [[objectStore managedObjectCache] fetchRequestsForResourcePath:rkURL.resourcePath]; NSArray* cachedObjects = [RKManagedObject objectsWithFetchRequests:fetchRequests]; for (id object in cachedObjects) { if ([object isKindOfClass:[RKManagedObject class]]) { @@ -192,7 +192,7 @@ // Before looking up NSManagedObjectIDs, need to save to ensure we do not have // temporary IDs for new objects prior to handing the objectIDs across threads - NSError* error = [self.managedObjectStore save]; + NSError* error = [objectStore save]; if (nil != error) { NSDictionary* infoDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:response, @"response", error, @"error", nil] retain]; [self performSelectorOnMainThread:@selector(informDelegateOfObjectLoadErrorWithInfoDictionary:) withObject:infoDictionary waitUntilDone:NO]; diff --git a/Code/ObjectMapping/RKObjectManager.m b/Code/ObjectMapping/RKObjectManager.m index 32508524..56f28be2 100644 --- a/Code/ObjectMapping/RKObjectManager.m +++ b/Code/ObjectMapping/RKObjectManager.m @@ -107,8 +107,11 @@ static RKObjectManager* globalManager = nil; } // Grab request through client to get HTTP AUTH & Headers - RKRequest* request = [self.client requestWithResourcePath:resourcePath delegate:nil callback:nil]; - return [RKObjectLoader loaderWithMapper:self.mapper request:request delegate:delegate]; + RKRequest* request = [self.client requestWithResourcePath:resourcePath delegate:nil callback:nil]; + RKObjectLoader* loader = [RKObjectLoader loaderWithMapper:self.mapper request:request delegate:delegate]; + loader.managedObjectStore = self.objectStore; + + return loader; } /////////////////////////////////////////////////////////////