RKDynamicObjectMapping Class Reference
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
-
delegate
A delegate to call back to determine the appropriate concrete object mapping to apply to the mappable data.
property -
objectMappingForDataBlock
A block to invoke to determine the appropriate concrete object mapping to apply to the mappable data.
property -
+ dynamicMapping
Return a new auto-released dynamic object mapping
-
+ dynamicMappingUsingBlock:
Return a new auto-released dynamic object mapping after yielding it to the block for configuration
-
– 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.
-
– objectMappingForDictionary:
Invoked by the RKObjectMapper and RKObjectMappingOperation to determine the appropriate RKObjectMapping to use when mapping the specified dictionary of mappable data.
Properties
Class Methods
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