Inherits from RKMapping : NSObject
Declared in RKDynamicMapping.h

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

Configuring Mapping Selection

Retrieving the Object Mapping for an Object Representation

Properties

objectMappings

Returns an array of object mappings that have been registered with the receiver.

@property (nonatomic, readonly) NSArray *objectMappings

Return Value

An array of RKObjectMapping objects registered with the receiver.

Declared In

RKDynamicMapping.h

Instance Methods

objectMappingForRepresentation:

Invoked by the RKMapperOperation and RKMappingOperation to determine the appropriate RKObjectMapping to use when mapping the given object representation.

- (RKObjectMapping *)objectMappingForRepresentation:(id)representation

Parameters

representation

The object representation that being mapped dynamically for which to determine the appropriate concrete mapping.

Return Value

The object mapping to be used to map the given object representation.

Declared In

RKDynamicMapping.h

setObjectMapping:whenValueOfKeyPath:isEqualTo:

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

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

Parameters

objectMapping

The mapping to be used when the value at the given key path is equal to the given value.

keyPath

The key path to retrieve the comparison value from in the object representation being mapped.

value

The value to be compared with the value at keyPath. If they are equal, the objectMapping will be used to map the representation.

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:

RKDynamicMapping *mapping = [RKDynamicMapping new];
[mapping setObjectMapping:boyMapping whenValueOfKeyPath:@"gender" isEqualTo:@"male"];
[mapping setObjectMapping:girlMapping whenValueOfKeyPath:@"gender" isEqualTo:@"female"];

Declared In

RKDynamicMapping.h

setObjectMappingForRepresentationBlock:

Sets a block to be invoked to determine the appropriate concrete object mapping with which to map an object representation.

- (void)setObjectMappingForRepresentationBlock:(RKDynamicMappingDelegateBlock)block

Parameters

block

The block object to invoke to select the object mapping with which to map the given object representation.

Declared In

RKDynamicMapping.h