Expose access to the RKMapperOperationDelegate to RKObjectRequestOperation subclasses. closes #1009

This commit is contained in:
Blake Watters
2012-11-29 23:34:35 -05:00
parent 648b159f9a
commit 89d0294dcd
3 changed files with 9 additions and 12 deletions

View File

@@ -84,11 +84,10 @@ static NSURL *RKRelativeURLFromURLAndResponseDescriptors(NSURL *URL, NSArray *re
return URL;
}
@interface RKManagedObjectRequestOperation () <RKMapperOperationDelegate>
@interface RKManagedObjectRequestOperation ()
// Core Data specific
@property (nonatomic, strong) NSManagedObjectContext *privateContext;
@property (nonatomic, copy) NSManagedObjectID *targetObjectID;
@property (nonatomic, strong) NSMutableDictionary *managedObjectsByKeyPath;
@property (nonatomic, strong) RKManagedObjectResponseMapperOperation *responseMapperOperation;
@property (nonatomic, strong, readwrite) NSError *error;
@property (nonatomic, strong, readwrite) RKMappingResult *mappingResult;
@@ -136,15 +135,6 @@ static NSURL *RKRelativeURLFromURLAndResponseDescriptors(NSURL *URL, NSArray *re
}
}
#pragma mark - RKMapperOperationDelegate methods
- (void)mapper:(RKMapperOperation *)mapper didFinishMappingOperation:(RKMappingOperation *)mappingOperation forKeyPath:(NSString *)keyPath
{
if ([mappingOperation.destinationObject isKindOfClass:[NSManagedObject class]]) {
[self.managedObjectsByKeyPath setObject:mappingOperation.destinationObject forKey:keyPath];
}
}
#pragma mark - RKObjectRequestOperation Overrides
- (void)cancel
@@ -177,6 +167,7 @@ static NSURL *RKRelativeURLFromURLAndResponseDescriptors(NSURL *URL, NSArray *re
self.responseMapperOperation = [[RKManagedObjectResponseMapperOperation alloc] initWithResponse:self.HTTPRequestOperation.response
data:self.HTTPRequestOperation.responseData
responseDescriptors:self.responseDescriptors];
self.responseMapperOperation.mapperDelegate = self;
self.responseMapperOperation.targetObjectID = self.targetObjectID;
self.responseMapperOperation.managedObjectContext = self.privateContext;
self.responseMapperOperation.managedObjectCache = self.managedObjectCache;

View File

@@ -20,6 +20,7 @@
#import "RKHTTPRequestOperation.h"
#import "RKMappingResult.h"
#import "RKMapperOperation.h"
/**
`RKObjectRequestOperation` is an `NSOperation` subclass that implements object mapping on the response body of an `NSHTTPResponse` loaded via an `RKHTTPRequestOperation`.
@@ -48,12 +49,16 @@
`RKObjectRequestOperation` is not able to perform object mapping that targets Core Data destination entities. Please refer to the `RKManagedObjectRequestOperation` subclass for details regarding performing a Core Data object request operation.
## Subclassing Notes
The `RKObjectRequestOperation` is a non-current `NSOperation` subclass and can be extended by subclassing and providing an implementation of the `main` method. It conforms to the `RKMapperOperationDelegate` protocol, providing access to the lifecycle of the mapping process to subclasses.
@see `RKResponseDescriptor`
@see `RKHTTPRequestOperation`
@see `RKMIMETypeSerialization`
@see `RKManagedObjectRequestOperation`
*/
@interface RKObjectRequestOperation : NSOperation
@interface RKObjectRequestOperation : NSOperation <RKMapperOperationDelegate>
///-----------------------------------------------
/// @name Initializing an Object Request Operation

View File

@@ -235,6 +235,7 @@ static NSString *RKStringDescribingURLResponseWithData(NSURLResponse *response,
data:self.HTTPRequestOperation.responseData
responseDescriptors:self.responseDescriptors];
self.responseMapperOperation.targetObject = self.targetObject;
self.responseMapperOperation.mapperDelegate = self;
[self.responseMapperOperation setQueuePriority:[self queuePriority]];
[self.responseMapperOperation setWillMapDeserializedResponseBlock:self.willMapDeserializedResponseBlock];
[[RKObjectRequestOperation responseMappingQueue] addOperation:self.responseMapperOperation];