mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 20:31:13 +08:00
make object loader retain self during send operations
This commit is contained in:
@@ -88,22 +88,26 @@
|
||||
}
|
||||
|
||||
- (void)send {
|
||||
[self retain];
|
||||
[self.request send];
|
||||
}
|
||||
|
||||
- (void)sendSynchronously {
|
||||
[self retain];
|
||||
RKResponse* response = [self.request sendSynchronously];
|
||||
[self loadObjectsFromResponse:response];
|
||||
}
|
||||
|
||||
#pragma mark Response Processing
|
||||
|
||||
- (BOOL)encounteredErrorWhileProcessingRequest:(RKResponse*)response {
|
||||
- (BOOL)encounteredErrorWhileProcessingRequest:(RKResponse*)response {
|
||||
if ([response isFailure]) {
|
||||
[_delegate objectLoader:self didFailWithError:response.failureError];
|
||||
[self release];
|
||||
return YES;
|
||||
} else if ([response isError]) {
|
||||
[_delegate objectLoader:self didFailWithError:[_mapper parseErrorFromString:[response bodyAsString]]];
|
||||
[self release];
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -127,6 +131,7 @@
|
||||
}
|
||||
|
||||
[_delegate objectLoader:self didLoadObjects:[NSArray arrayWithArray:objects]];
|
||||
[self release];
|
||||
}
|
||||
|
||||
- (void)informDelegateOfObjectLoadErrorWithInfoDictionary:(NSDictionary*)dictionary {
|
||||
@@ -141,6 +146,7 @@
|
||||
NSError *rkError = [NSError errorWithDomain:RKRestKitErrorDomain code:RKObjectLoaderRemoteSystemError userInfo:userInfo];
|
||||
|
||||
[_delegate objectLoader:self didFailWithError:rkError];
|
||||
[self release];
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +154,8 @@
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
RKManagedObjectStore* objectStore = self.managedObjectStore;
|
||||
|
||||
NSLog(@"The response body is %@", [response bodyAsString]);
|
||||
|
||||
// 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?
|
||||
// The issue is that not specifying the object results in new objects being created
|
||||
@@ -250,6 +258,7 @@
|
||||
}
|
||||
|
||||
- (void)requestDidCancelLoad:(RKRequest*)request {
|
||||
[self release];
|
||||
if ([_delegate respondsToSelector:@selector(requestDidCancelLoad:)]) {
|
||||
[(NSObject<RKRequestDelegate>*)_delegate requestDidCancelLoad:request];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user