mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-29 21:25:51 +08:00
Expose access to the RKMapperOperationDelegate to RKObjectRequestOperation subclasses. closes #1009
This commit is contained in:
@@ -84,11 +84,10 @@ static NSURL *RKRelativeURLFromURLAndResponseDescriptors(NSURL *URL, NSArray *re
|
|||||||
return URL;
|
return URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface RKManagedObjectRequestOperation () <RKMapperOperationDelegate>
|
@interface RKManagedObjectRequestOperation ()
|
||||||
// Core Data specific
|
// Core Data specific
|
||||||
@property (nonatomic, strong) NSManagedObjectContext *privateContext;
|
@property (nonatomic, strong) NSManagedObjectContext *privateContext;
|
||||||
@property (nonatomic, copy) NSManagedObjectID *targetObjectID;
|
@property (nonatomic, copy) NSManagedObjectID *targetObjectID;
|
||||||
@property (nonatomic, strong) NSMutableDictionary *managedObjectsByKeyPath;
|
|
||||||
@property (nonatomic, strong) RKManagedObjectResponseMapperOperation *responseMapperOperation;
|
@property (nonatomic, strong) RKManagedObjectResponseMapperOperation *responseMapperOperation;
|
||||||
@property (nonatomic, strong, readwrite) NSError *error;
|
@property (nonatomic, strong, readwrite) NSError *error;
|
||||||
@property (nonatomic, strong, readwrite) RKMappingResult *mappingResult;
|
@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
|
#pragma mark - RKObjectRequestOperation Overrides
|
||||||
|
|
||||||
- (void)cancel
|
- (void)cancel
|
||||||
@@ -177,6 +167,7 @@ static NSURL *RKRelativeURLFromURLAndResponseDescriptors(NSURL *URL, NSArray *re
|
|||||||
self.responseMapperOperation = [[RKManagedObjectResponseMapperOperation alloc] initWithResponse:self.HTTPRequestOperation.response
|
self.responseMapperOperation = [[RKManagedObjectResponseMapperOperation alloc] initWithResponse:self.HTTPRequestOperation.response
|
||||||
data:self.HTTPRequestOperation.responseData
|
data:self.HTTPRequestOperation.responseData
|
||||||
responseDescriptors:self.responseDescriptors];
|
responseDescriptors:self.responseDescriptors];
|
||||||
|
self.responseMapperOperation.mapperDelegate = self;
|
||||||
self.responseMapperOperation.targetObjectID = self.targetObjectID;
|
self.responseMapperOperation.targetObjectID = self.targetObjectID;
|
||||||
self.responseMapperOperation.managedObjectContext = self.privateContext;
|
self.responseMapperOperation.managedObjectContext = self.privateContext;
|
||||||
self.responseMapperOperation.managedObjectCache = self.managedObjectCache;
|
self.responseMapperOperation.managedObjectCache = self.managedObjectCache;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#import "RKHTTPRequestOperation.h"
|
#import "RKHTTPRequestOperation.h"
|
||||||
#import "RKMappingResult.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`.
|
`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.
|
`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 `RKResponseDescriptor`
|
||||||
@see `RKHTTPRequestOperation`
|
@see `RKHTTPRequestOperation`
|
||||||
@see `RKMIMETypeSerialization`
|
@see `RKMIMETypeSerialization`
|
||||||
@see `RKManagedObjectRequestOperation`
|
@see `RKManagedObjectRequestOperation`
|
||||||
*/
|
*/
|
||||||
@interface RKObjectRequestOperation : NSOperation
|
@interface RKObjectRequestOperation : NSOperation <RKMapperOperationDelegate>
|
||||||
|
|
||||||
///-----------------------------------------------
|
///-----------------------------------------------
|
||||||
/// @name Initializing an Object Request Operation
|
/// @name Initializing an Object Request Operation
|
||||||
|
|||||||
@@ -235,6 +235,7 @@ static NSString *RKStringDescribingURLResponseWithData(NSURLResponse *response,
|
|||||||
data:self.HTTPRequestOperation.responseData
|
data:self.HTTPRequestOperation.responseData
|
||||||
responseDescriptors:self.responseDescriptors];
|
responseDescriptors:self.responseDescriptors];
|
||||||
self.responseMapperOperation.targetObject = self.targetObject;
|
self.responseMapperOperation.targetObject = self.targetObject;
|
||||||
|
self.responseMapperOperation.mapperDelegate = self;
|
||||||
[self.responseMapperOperation setQueuePriority:[self queuePriority]];
|
[self.responseMapperOperation setQueuePriority:[self queuePriority]];
|
||||||
[self.responseMapperOperation setWillMapDeserializedResponseBlock:self.willMapDeserializedResponseBlock];
|
[self.responseMapperOperation setWillMapDeserializedResponseBlock:self.willMapDeserializedResponseBlock];
|
||||||
[[RKObjectRequestOperation responseMappingQueue] addOperation:self.responseMapperOperation];
|
[[RKObjectRequestOperation responseMappingQueue] addOperation:self.responseMapperOperation];
|
||||||
|
|||||||
Reference in New Issue
Block a user