Kill use of delegate on dynamic mapping in favor of blocks and declarative matching

This commit is contained in:
Blake Watters
2012-09-11 18:36:26 -04:00
parent ec8181dd78
commit 382f9f8ceb
2 changed files with 6 additions and 31 deletions

View File

@@ -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
/**

View File

@@ -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) {