mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-06-19 18:24:12 +08:00
RKObjectLoader should be set up with the object managers client, not the shared one.
This fixes support for apps using multiple baseURLs via multiple clients or managers.
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
NSString* _keyPath;
|
||||
RKManagedObjectStore* _managedObjectStore;
|
||||
NSManagedObjectID* _targetObjectID;
|
||||
RKClient* _client;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,10 +90,12 @@
|
||||
* Return an auto-released loader with with an object mapper, a request, and a delegate
|
||||
*/
|
||||
+ (id)loaderWithResourcePath:(NSString*)resourcePath mapper:(RKObjectMapper*)mapper delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
|
||||
+ (id)loaderWithResourcePath:(NSString*)resourcePath client:(RKClient*)client mapper:(RKObjectMapper*)mapper delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
|
||||
|
||||
/**
|
||||
* Initialize a new object loader with an object mapper, a request, and a delegate
|
||||
*/
|
||||
- (id)initWithResourcePath:(NSString*)resourcePath mapper:(RKObjectMapper*)mapper delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
|
||||
- (id)initWithResourcePath:(NSString*)resourcePath mapper:(RKObjectMapper*)mapper delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
|
||||
- (id)initWithResourcePath:(NSString*)resourcePath client:(RKClient*)client mapper:(RKObjectMapper*)mapper delegate:(NSObject<RKObjectLoaderDelegate>*)delegate;
|
||||
|
||||
@end
|
||||
|
||||
@@ -22,16 +22,24 @@
|
||||
keyPath = _keyPath, managedObjectStore = _managedObjectStore;
|
||||
|
||||
+ (id)loaderWithResourcePath:(NSString*)resourcePath mapper:(RKObjectMapper*)mapper delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
return [[[self alloc] initWithResourcePath:resourcePath mapper:mapper delegate:delegate] autorelease];
|
||||
return [self loaderWithResourcePath:resourcePath client:[RKClient sharedClient] mapper:mapper delegate:delegate];
|
||||
}
|
||||
|
||||
+ (id)loaderWithResourcePath:(NSString*)resourcePath client:(RKClient*)client mapper:(RKObjectMapper*)mapper delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
return [[[self alloc] initWithResourcePath:resourcePath client:client mapper:mapper delegate:delegate] autorelease];
|
||||
}
|
||||
|
||||
- (id)initWithResourcePath:(NSString*)resourcePath mapper:(RKObjectMapper*)mapper delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
if (self = [self initWithURL:[[RKClient sharedClient] URLForResourcePath:resourcePath] delegate:delegate]) {
|
||||
return [self initWithResourcePath:resourcePath client:[RKClient sharedClient] mapper:mapper delegate:delegate];
|
||||
}
|
||||
|
||||
- (id)initWithResourcePath:(NSString*)resourcePath client:(RKClient*)client mapper:(RKObjectMapper*)mapper delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
if (self = [self initWithURL:[client URLForResourcePath:resourcePath] delegate:delegate]) {
|
||||
_mapper = [mapper retain];
|
||||
self.managedObjectStore = nil;
|
||||
_targetObjectID = nil;
|
||||
|
||||
[[RKClient sharedClient] setupRequest:self];
|
||||
_client = [client retain];
|
||||
[_client setupRequest:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -47,6 +55,8 @@
|
||||
_targetObject = nil;
|
||||
[_targetObjectID release];
|
||||
_targetObjectID = nil;
|
||||
[_client release];
|
||||
_client = nil;
|
||||
self.managedObjectStore = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ static RKObjectManager* sharedManager = nil;
|
||||
}
|
||||
|
||||
- (RKObjectLoader*)objectLoaderWithResourcePath:(NSString*)resourcePath delegate:(NSObject<RKObjectLoaderDelegate>*)delegate {
|
||||
RKObjectLoader* loader = [RKObjectLoader loaderWithResourcePath:resourcePath mapper:self.mapper delegate:delegate];
|
||||
RKObjectLoader* loader = [RKObjectLoader loaderWithResourcePath:resourcePath client:_client mapper:self.mapper delegate:delegate];
|
||||
loader.managedObjectStore = self.objectStore;
|
||||
|
||||
return loader;
|
||||
|
||||
Reference in New Issue
Block a user