mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-17 12:20:20 +08:00
Kill use of delegate on dynamic mapping in favor of blocks and declarative matching
This commit is contained in:
@@ -21,16 +21,6 @@
|
||||
#import "RKMapping.h"
|
||||
#import "RKObjectMapping.h"
|
||||
|
||||
/**
|
||||
Return the appropriate object mapping given a mappable data
|
||||
*/
|
||||
@protocol RKDynamicMappingDelegate <NSObject>
|
||||
|
||||
@required
|
||||
- (RKObjectMapping *)objectMappingForData:(id)data;
|
||||
|
||||
@end
|
||||
|
||||
#ifdef NS_BLOCKS_AVAILABLE
|
||||
typedef RKObjectMapping *(^RKDynamicMappingDelegateBlock)(id);
|
||||
#endif
|
||||
@@ -40,17 +30,7 @@ typedef RKObjectMapping *(^RKDynamicMappingDelegateBlock)(id);
|
||||
object mapping to apply at mapping time. This allows you to map very similar payloads
|
||||
differently depending on the type of data contained therein.
|
||||
*/
|
||||
@interface RKDynamicMapping : RKMapping {
|
||||
NSMutableArray *_matchers;
|
||||
}
|
||||
|
||||
/**
|
||||
A delegate to call back to determine the appropriate concrete object mapping
|
||||
to apply to the mappable data.
|
||||
|
||||
@see RKDynamicMappingDelegate
|
||||
*/
|
||||
@property (nonatomic, weak) id<RKDynamicMappingDelegate> delegate;
|
||||
@interface RKDynamicMapping : RKMapping
|
||||
|
||||
#ifdef NS_BLOCKS_AVAILABLE
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#undef RKLogComponent
|
||||
#define RKLogComponent lcl_cRestKitObjectMapping
|
||||
|
||||
@interface RKDynamicMapping ()
|
||||
@property (nonatomic, strong) NSMutableArray *matchers;
|
||||
@end
|
||||
|
||||
@implementation RKDynamicMapping
|
||||
|
||||
@@ -55,7 +58,7 @@
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_matchers = [NSMutableArray new];
|
||||
self.matchers = [NSMutableArray new];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -84,15 +87,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise consult the delegates
|
||||
if (self.delegate) {
|
||||
mapping = [self.delegate objectMappingForData:data];
|
||||
if (mapping) {
|
||||
RKLogTrace(@"Found dynamic delegate match. Delegate = %@", self.delegate);
|
||||
return mapping;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise consult the block
|
||||
if (self.objectMappingForDataBlock) {
|
||||
mapping = self.objectMappingForDataBlock(data);
|
||||
if (mapping) {
|
||||
|
||||
Reference in New Issue
Block a user