Inherits from RKObjectMappingDefinition : NSObject
Declared in RKDynamicObjectMapping.h
RKDynamicObjectMapping.m

Overview

Defines a dynamic object mapping that determines the appropriate concrete object mapping to apply at mapping time. This allows you to map very similar payloads differently depending on the type of data contained therein.

Tasks

Properties

delegate

A delegate to call back to determine the appropriate concrete object mapping to apply to the mappable data.

@property (nonatomic, assign) id<> delegate

Declared In

RKDynamicObjectMapping.h

objectMappingForDataBlock

A block to invoke to determine the appropriate concrete object mapping to apply to the mappable data.

@property (nonatomic, copy) RKDynamicObjectMappingDelegateBlock objectMappingForDataBlock

Declared In

RKDynamicObjectMapping.h

Class Methods

dynamicMapping

Return a new auto-released dynamic object mapping

+ (RKDynamicObjectMapping *)dynamicMapping

Declared In

RKDynamicObjectMapping.h

dynamicMappingUsingBlock:

Return a new auto-released dynamic object mapping after yielding it to the block for configuration

+ (RKDynamicObjectMapping *)dynamicMappingUsingBlock:(void ( ^ ) ( RKDynamicObjectMapping *dynamicMapping ))block

Declared In

RKDynamicObjectMapping.h

Instance Methods

objectMappingForDictionary:

Invoked by the RKObjectMapper and RKObjectMappingOperation to determine the appropriate RKObjectMapping to use when mapping the specified dictionary of mappable data.

- (RKObjectMapping *)objectMappingForDictionary:(NSDictionary *)dictionary

Declared In

RKDynamicObjectMapping.h

setObjectMapping:whenValueOfKeyPath:isEqualTo:

Defines a dynamic mapping rule stating that when the value of the key property matches the specified value, the objectMapping should be used.

- (void)setObjectMapping:(RKObjectMapping *)objectMapping whenValueOfKeyPath:(NSString *)keyPath isEqualTo:(id)value

Discussion

For example, suppose that we have a JSON fragment for a person that we want to map differently based on the gender of the person. When the gender is ‘male’, we want to use the Boy class and when then the gender is ‘female’ we want to use the Girl class. We might define our dynamic mapping like so:

RKDynamicObjectMapping *mapping = [RKDynamicObjectMapping dynamicMapping];
[mapping setObjectMapping:boyMapping whenValueOfKeyPath:@"gender" isEqualTo:@"male"];
[mapping setObjectMapping:boyMapping whenValueOfKeyPath:@"gender" isEqualTo:@"female"];

Declared In

RKDynamicObjectMapping.h