RKObjectMapping Class Reference
Inherits from | RKObjectMappingDefinition : NSObject |
Conforms to | NSCopying |
Declared in | RKObjectMapping.h RKObjectMapping.m |
Overview
An object mapping defines the rules for transforming a key-value coding compliant object into another representation. The mapping is defined in terms of a source object class and a collection of rules defining how keyPaths should be transformed into target attributes and relationships.
There are two types of transformations possible:
- keyPath to attribute. Defines that the value found at the keyPath should be transformed and assigned to the property specified by the attribute. The transformation to be performed is determined by inspecting the type of the target property at runtime.
- keyPath to relationship. Defines that the value found at the keyPath should be transformed into another object instance and assigned to the property specified by the relationship. Relationships are processed using an object mapping as well.
Through the use of relationship mappings, an arbitrarily complex object graph can be mapped for you.
Instances of RKObjectMapping are used to configure RKObjectMappingOperation instances, which actually perform the mapping work. Both object loading and serialization are defined in terms of object mappings.
Defines the inteface for configuring time and date formatting handling within RestKit object mappings. For performance reasons, RestKit reuses a pool of date formatters rather than constructing them at mapping time. This collection of date formatters can be configured on a per-object mapping or application-wide basis using the static methods exposed in this category.
Tasks
Other Methods
-
objectClass
The target class this object mapping is defining rules for
property -
objectClassName
The name of the target class the receiver defines a mapping for.
property -
mappings
The aggregate collection of attribute and relationship mappings within this object mapping
property -
attributeMappings
The collection of attribute mappings within this object mapping
property -
relationshipMappings
The collection of relationship mappings within this object mapping
property -
mappedKeyPaths
The collection of mappable keyPaths that are defined within this object mapping. These keyPaths refer to keys within the source object being mapped (i.e. the parsed JSON payload).
property -
setDefaultValueForMissingAttributes
When YES, any attributes that have mappings defined but are not present within the source object will be set to nil, clearing any existing value.
property -
setNilForMissingRelationships
When YES, any relationships that have mappings defined but are not present within the source object will be set to nil, clearing any existing value.
property -
performKeyValueValidation
When YES, RestKit will invoke key-value validation at object mapping time.
property -
ignoreUnknownKeyPaths
When YES, RestKit will check that the object being mapped is key-value coding compliant for the mapped key. If it is not, the attribute/relationship mapping will be ignored and mapping will continue. When NO, unknown keyPath mappings will generate NSUnknownKeyException errors for the unknown keyPath.
property -
dateFormatters
An array of NSDateFormatter objects to use when mapping string values into NSDate attributes on the target objectClass. Each date formatter will be invoked with the string value being mapped until one of the date formatters does not return nil.
property -
preferredDateFormatter
The NSFormatter object for your application’s preferred date and time configuration. This date formatter will be used when generating string representations of NSDate attributes (i.e. during serialization to URL form encoded or JSON format).
property -
+ mappingForClass:
Returns an object mapping for the specified class that is ready for configuration
-
+ mappingForClassWithName:
Creates and returns an object mapping for the class with the given name
-
+ serializationMapping
Returns an object mapping useful for configuring a serialization mapping. The object class is configured as NSMutableDictionary
-
+ mappingForClass:usingBlock:
Returns an object mapping targeting the specified class. The RKObjectMapping instance will be yieled to the block so that you can perform on the fly configuration without having to obtain a reference variable for the mapping.
-
+ serializationMappingUsingBlock:
Returns serialization mapping for encoding a local object to a dictionary for transport. The RKObjectMapping instance will be yieled to the block so that you can perform on the fly configuration without having to obtain a reference variable for the mapping.
-
– addAttributeMapping:
Add a configured attribute mapping to this object mapping
-
– addRelationshipMapping:
Add a configured attribute mapping to this object mapping
-
– mappingForKeyPath:
Returns the attribute or relationship mapping for the given source keyPath.
-
– mappingForSourceKeyPath:
Returns the attribute or relationship mapping for the given source keyPath.
-
– mappingForDestinationKeyPath:
Returns the attribute or relationship mapping for the given destination keyPath.
-
– mappingForAttribute:
Returns the attribute mapping targeting the specified attribute on the destination object
-
– mappingForRelationship:
Returns the relationship mapping targeting the specified relationship on the destination object
-
– mapAttributes:
Define an attribute mapping for one or more keyPaths where the source keyPath and destination attribute property have the same name.
-
– mapAttributesFromSet:
Defines an attribute mapping for each string attribute in the collection where the source keyPath and the destination attribute property have the same name.
-
– mapAttributesFromArray:
Defines an attribute mapping for each string attribute in the collection where the source keyPath and the destination attribute property have the same name.
-
– mapRelationship:withMapping:
Defines a relationship mapping for a key where the source keyPath and the destination relationship property have the same name.
-
– hasMany:withMapping:
Syntactic sugar to improve readability when defining a relationship mapping. Implies that the mapping targets a one-to-many relationship nested within the source data.
-
– hasOne:withMapping:
Syntactic sugar to improve readability when defining a relationship mapping. Implies that the mapping targets a one-to-one relationship nested within the source data.
-
– mapKeyPath:toAttribute:
Instantiate and add an RKObjectAttributeMapping instance targeting a keyPath within the mappable source data to an attribute on the target object.
-
– mapKeyPath:toRelationship:withMapping:
Instantiate and add an RKObjectRelationshipMapping instance targeting a keyPath within the mappable source data to a relationship property on the target object.
-
– mapKeyPath:toRelationship:withMapping:serialize:
Instantiate and add an RKObjectRelationshipMapping instance targeting a keyPath within the mappable source data to a relationship property on the target object.
-
– mapKeyPathsToAttributes:
Quickly define a group of attribute mappings using alternating keyPath and attribute names. You must provide an equal number of keyPath and attribute pairs or an exception will be generated.
-
– mapKeyOfNestedDictionaryToAttribute:
Configures a sub-key mapping for cases where JSON has been nested underneath a key named after an attribute.
-
– attributeMappingForKeyOfNestedDictionary
Returns the attribute mapping targeting the key of a nested dictionary in the source JSON. This attribute mapping corresponds to the attributeName configured via mapKeyOfNestedDictionaryToAttribute:
-
– removeAllMappings
Removes all currently configured attribute and relationship mappings from the object mapping
-
– removeMapping:
Removes an instance of an attribute or relationship mapping from the object mapping
-
– removeMappingForKeyPath:
Remove the attribute or relationship mapping for the specified source keyPath
-
– inverseMapping
Generates an inverse mapping for the rules specified within this object mapping. This can be used to quickly generate a corresponding serialization mapping from a configured object mapping. The inverse mapping will have the source and destination keyPaths swapped for all attribute and relationship mappings.
-
– defaultValueForMissingAttribute:
Returns the default value to be assigned to the specified attribute when it is missing from a mappable payload.
-
– mappableObjectForData:
Returns an auto-released object that can be used to apply this object mapping given a set of mappable data. For transient objects, this generally returns an instance of the objectClass. For Core Data backed persistent objects, mappableData will be inspected to search for primary key data to lookup existing object instances.
-
– classForProperty:
Returns the class of the attribute or relationship property of the target objectClass
DateAndTimeFormatting Methods
-
+ defaultDateFormatters
Returns the collection of default date formatters that will be used for all object mappings that have not been configured specifically.
-
+ setDefaultDateFormatters:
Sets the collection of default date formatters to the specified array. The array should contain configured instances of NSDateFormatter in the order in which you want them applied during object mapping operations.
-
+ addDefaultDateFormatter:
Adds a date formatter instance to the default collection
-
+ addDefaultDateFormatterForString:inTimeZone:
Convenience method for quickly constructing a date formatter and adding it to the collection of default date formatters. The locale is auto-configured to en_US_POSIX
-
+ preferredDateFormatter
Returns the preferred date formatter to use when generating NSString representations from NSDate attributes. This type of transformation occurs when RestKit is mapping local objects into JSON or form encoded serializations that do not have a native time construct.
-
+ setPreferredDateFormatter:
Sets the preferred date formatter to use when generating NSString representations from NSDate attributes. This type of transformation occurs when RestKit is mapping local objects into JSON or form encoded serializations that do not have a native time construct.
Properties
attributeMappings
The collection of attribute mappings within this object mapping
@property (nonatomic, readonly) NSArray *attributeMappings
Declared In
RKObjectMapping.h
dateFormatters
An array of NSDateFormatter objects to use when mapping string values into NSDate attributes on the target objectClass. Each date formatter will be invoked with the string value being mapped until one of the date formatters does not return nil.
@property (nonatomic, retain) NSArray *dateFormatters
Discussion
Defaults to the application-wide collection of date formatters configured via: [RKObjectMapping setDefaultDateFormatters:]
Declared In
RKObjectMapping.h
ignoreUnknownKeyPaths
When YES, RestKit will check that the object being mapped is key-value coding compliant for the mapped key. If it is not, the attribute/relationship mapping will be ignored and mapping will continue. When NO, unknown keyPath mappings will generate NSUnknownKeyException errors for the unknown keyPath.
@property (nonatomic, assign) BOOL ignoreUnknownKeyPaths
Discussion
Defaults to NO to help the developer catch incorrect mapping configurations during development.
Default: NO
Declared In
RKObjectMapping.h
mappedKeyPaths
The collection of mappable keyPaths that are defined within this object mapping. These keyPaths refer to keys within the source object being mapped (i.e. the parsed JSON payload).
@property (nonatomic, readonly) NSArray *mappedKeyPaths
Declared In
RKObjectMapping.h
mappings
The aggregate collection of attribute and relationship mappings within this object mapping
@property (nonatomic, readonly) NSArray *mappings
Declared In
RKObjectMapping.h
objectClass
The target class this object mapping is defining rules for
@property (nonatomic, assign) Class objectClass
Declared In
RKObjectMapping.h
objectClassName
The name of the target class the receiver defines a mapping for.
@property (nonatomic, copy) NSString *objectClassName
See Also
Declared In
RKObjectMapping.h
performKeyValueValidation
When YES, RestKit will invoke key-value validation at object mapping time.
@property (nonatomic, assign) BOOL performKeyValueValidation
Discussion
Default: YES
Declared In
RKObjectMapping.h
preferredDateFormatter
The NSFormatter object for your application’s preferred date and time configuration. This date formatter will be used when generating string representations of NSDate attributes (i.e. during serialization to URL form encoded or JSON format).
@property (nonatomic, retain) NSFormatter *preferredDateFormatter
Discussion
Defaults to the application-wide preferred date formatter configured via: [RKObjectMapping setPreferredDateFormatter:]
Declared In
RKObjectMapping.h
relationshipMappings
The collection of relationship mappings within this object mapping
@property (nonatomic, readonly) NSArray *relationshipMappings
Declared In
RKObjectMapping.h
setDefaultValueForMissingAttributes
When YES, any attributes that have mappings defined but are not present within the source object will be set to nil, clearing any existing value.
@property (nonatomic, assign, getter=shouldSetDefaultValueForMissingAttributes) BOOL setDefaultValueForMissingAttributes
Declared In
RKObjectMapping.h
setNilForMissingRelationships
When YES, any relationships that have mappings defined but are not present within the source object will be set to nil, clearing any existing value.
@property (nonatomic, assign) BOOL setNilForMissingRelationships
Declared In
RKObjectMapping.h
Class Methods
addDefaultDateFormatter:
Adds a date formatter instance to the default collection
+ (void)addDefaultDateFormatter:(NSFormatter *)dateFormatter
Parameters
- dateFormatter
An NSFormatter object to append to the end of the default formatters collection
See Also
Declared In
RKObjectMapping.h
addDefaultDateFormatterForString:inTimeZone:
Convenience method for quickly constructing a date formatter and adding it to the collection of default date formatters. The locale is auto-configured to en_US_POSIX
+ (void)addDefaultDateFormatterForString:(NSString *)dateFormatString inTimeZone:(NSTimeZone *)nilOrTimeZone
Parameters
- dateFormatString
The dateFormat string to assign to the newly constructed NSDateFormatter instance
- nilOrTimeZone
The NSTimeZone object to configure on the NSDateFormatter instance. Defaults to UTC time.
Return Value
A new NSDateFormatter will be appended to the defaultDateFormatters with the specified date format and time zone
Declared In
RKObjectMapping.h
defaultDateFormatters
Returns the collection of default date formatters that will be used for all object mappings that have not been configured specifically.
+ (NSArray *)defaultDateFormatters
Return Value
An array of NSFormatter objects used when mapping strings into NSDate attributes
Discussion
Out of the box, RestKit initializes the following default date formatters for you in the UTC time zone:
* yyyy-MM-dd'T'HH:mm:ss'Z'
* MM/dd/yyyy
Declared In
RKObjectMapping.h
mappingForClass:
Returns an object mapping for the specified class that is ready for configuration
+ (id)mappingForClass:(Class)objectClass
Declared In
RKObjectMapping.h
mappingForClass:usingBlock:
Returns an object mapping targeting the specified class. The RKObjectMapping instance will be yieled to the block so that you can perform on the fly configuration without having to obtain a reference variable for the mapping.
+ (id)mappingForClass:(Class)objectClass usingBlock:(void ( ^ ) ( RKObjectMapping *mapping ))block
Discussion
For example, consider we have a one-off request that will load a few attributes for our object. Using blocks, this is very succinct:
[[RKObjectManager sharedManager] postObject:self usingBlock:^(RKObjectLoader* loader) {
loader.objectMapping = [RKObjectMapping mappingForClass:[Person class] usingBlock:^(RKObjectMapping* mapping) {
[mapping mapAttributes:@"email", @"first_name", nil];
}];
}];
Declared In
RKObjectMapping.h
mappingForClassWithName:
Creates and returns an object mapping for the class with the given name
+ (id)mappingForClassWithName:(NSString *)objectClassName
Parameters
- objectClassName
The name of the class the mapping is for.
Return Value
A new object mapping with for the class with given name.
Declared In
RKObjectMapping.h
preferredDateFormatter
Returns the preferred date formatter to use when generating NSString representations from NSDate attributes. This type of transformation occurs when RestKit is mapping local objects into JSON or form encoded serializations that do not have a native time construct.
+ (NSFormatter *)preferredDateFormatter
Return Value
The preferred NSFormatter object to use when serializing dates into strings
Discussion
Defaults to a date formatter configured for the UTC Time Zone with a format string of “yyyy-MM-dd HH:mm:ss Z”
Declared In
RKObjectMapping.h
serializationMapping
Returns an object mapping useful for configuring a serialization mapping. The object class is configured as NSMutableDictionary
+ (id)serializationMapping
Declared In
RKObjectMapping.h
serializationMappingUsingBlock:
Returns serialization mapping for encoding a local object to a dictionary for transport. The RKObjectMapping instance will be yieled to the block so that you can perform on the fly configuration without having to obtain a reference variable for the mapping.
+ (id)serializationMappingUsingBlock:(void ( ^ ) ( RKObjectMapping *serializationMapping ))block
Discussion
For example, consider we have a one-off request within which we want to post a subset of our object data. Using blocks, this is very succinct:
- (BOOL)changePassword:(NSString*)newPassword error:(NSError**)error {
if ([self validatePassword:newPassword error:error]) {
self.password = newPassword;
[[RKObjectManager sharedManager] putObject:self delegate:self block:^(RKObjectLoader* loader) {
loader.serializationMapping = [RKObjectMapping serializationMappingUsingBlock:^(RKObjectMapping* mapping) {
[mapping mapAttributes:@"password", nil];
}];
}];
}
}
Using the block forms we are able to quickly configure and send this request on the fly.
Declared In
RKObjectMapping.h
setDefaultDateFormatters:
Sets the collection of default date formatters to the specified array. The array should contain configured instances of NSDateFormatter in the order in which you want them applied during object mapping operations.
+ (void)setDefaultDateFormatters:(NSArray *)dateFormatters
Parameters
- dateFormatters
An array of date formatters to replace the existing defaults
See Also
Declared In
RKObjectMapping.h
setPreferredDateFormatter:
Sets the preferred date formatter to use when generating NSString representations from NSDate attributes. This type of transformation occurs when RestKit is mapping local objects into JSON or form encoded serializations that do not have a native time construct.
+ (void)setPreferredDateFormatter:(NSFormatter *)dateFormatter
Parameters
- dateFormatter
The NSFormatter object to designate as the new preferred instance
Declared In
RKObjectMapping.h
Instance Methods
addAttributeMapping:
Add a configured attribute mapping to this object mapping
- (void)addAttributeMapping:(RKObjectAttributeMapping *)mapping
See Also
Declared In
RKObjectMapping.h
addRelationshipMapping:
Add a configured attribute mapping to this object mapping
- (void)addRelationshipMapping:(RKObjectRelationshipMapping *)mapping
See Also
Declared In
RKObjectMapping.h
attributeMappingForKeyOfNestedDictionary
Returns the attribute mapping targeting the key of a nested dictionary in the source JSON. This attribute mapping corresponds to the attributeName configured via mapKeyOfNestedDictionaryToAttribute:
- (RKObjectAttributeMapping *)attributeMappingForKeyOfNestedDictionary
Return Value
An attribute mapping for the key of a nested dictionary being mapped or nil
Declared In
RKObjectMapping.h
classForProperty:
Returns the class of the attribute or relationship property of the target objectClass
- (Class)classForProperty:(NSString *)propertyName
Parameters
- propertyName
The name of the property we would like to retrieve the type of
Discussion
Given the name of a string property, this will return an NSString, etc.
Declared In
RKObjectMapping.h
defaultValueForMissingAttribute:
Returns the default value to be assigned to the specified attribute when it is missing from a mappable payload.
- (id)defaultValueForMissingAttribute:(NSString *)attributeName
Discussion
The default implementation returns nil for transient object mappings. On managed object mappings, the default value returned from the Entity definition will be used.
Declared In
RKObjectMapping.h
hasMany:withMapping:
Syntactic sugar to improve readability when defining a relationship mapping. Implies that the mapping targets a one-to-many relationship nested within the source data.
- (void)hasMany:(NSString *)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping
Declared In
RKObjectMapping.h
hasOne:withMapping:
Syntactic sugar to improve readability when defining a relationship mapping. Implies that the mapping targets a one-to-one relationship nested within the source data.
- (void)hasOne:(NSString *)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping
Declared In
RKObjectMapping.h
inverseMapping
Generates an inverse mapping for the rules specified within this object mapping. This can be used to quickly generate a corresponding serialization mapping from a configured object mapping. The inverse mapping will have the source and destination keyPaths swapped for all attribute and relationship mappings.
- (RKObjectMapping *)inverseMapping
Declared In
RKObjectMapping.h
mapAttributes:
Define an attribute mapping for one or more keyPaths where the source keyPath and destination attribute property have the same name.
- (void)mapAttributes:(NSString *)attributeKey, ...
Parameters
- attributeKey
A key-value coding key corresponding to a value in the mappable source object and an attribute on the destination class that have the same name.
Discussion
For example, given the transformation from a JSON dictionary:
{"name": "My Name", "age": 28}
To a Person class with corresponding name & age properties, we could configure the attribute mappings via:
[mapping mapAttributes:@"name", @"age", nil];
Declared In
RKObjectMapping.h
mapAttributesFromArray:
Defines an attribute mapping for each string attribute in the collection where the source keyPath and the destination attribute property have the same name.
- (void)mapAttributesFromArray:(NSArray *)set
Parameters
- array
An array of string attribute keyPaths to deifne mappings for
Discussion
For example, given the transformation from a JSON dictionary:
{"name": "My Name", "age": 28}
To a Person class with corresponding name & age properties, we could configure the attribute mappings via:
[mapping mapAttributesFromSet:[NSArray arrayWithObjects:@"name", @"age", nil]];
Declared In
RKObjectMapping.h
mapAttributesFromSet:
Defines an attribute mapping for each string attribute in the collection where the source keyPath and the destination attribute property have the same name.
- (void)mapAttributesFromSet:(NSSet *)set
Parameters
- set
A set of string attribute keyPaths to deifne mappings for
Discussion
For example, given the transformation from a JSON dictionary:
{"name": "My Name", "age": 28}
To a Person class with corresponding name & age properties, we could configure the attribute mappings via:
[mapping mapAttributesFromSet:[NSSet setWithObjects:@"name", @"age", nil]];
Declared In
RKObjectMapping.h
mapKeyOfNestedDictionaryToAttribute:
Configures a sub-key mapping for cases where JSON has been nested underneath a key named after an attribute.
- (void)mapKeyOfNestedDictionaryToAttribute:(NSString *)attributeName
Discussion
For example, consider the following JSON:
{ "users":
{
"blake": { "id": 1234, "email": "[email protected]" },
"rachit": { "id": 5678", "email": "[email protected]" }
}
}
We can configure our mappings to handle this in the following form:
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[User class]];
mapping.forceCollectionMapping = YES; // RestKit cannot infer this is a collection, so we force it
[mapping mapKeyOfNestedDictionaryToAttribute:@"firstName"];
[mapping mapFromKeyPath:@"(firstName).id" toAttribute:"userID"];
[mapping mapFromKeyPath:@"(firstName).email" toAttribute:"email"];
[[RKObjectManager sharedManager].mappingProvider setObjectMapping:mapping forKeyPath:@"users"];
Declared In
RKObjectMapping.h
mapKeyPath:toAttribute:
Instantiate and add an RKObjectAttributeMapping instance targeting a keyPath within the mappable source data to an attribute on the target object.
- (void)mapKeyPath:(NSString *)sourceKeyPath toAttribute:(NSString *)destinationAttribute
Parameters
- sourceKeyPath
A key-value coding keyPath to fetch the mappable value from
- destinationAttribute
The attribute name to assign the mapped value to
Discussion
Used to quickly define mappings where the source value is deeply nested in the mappable data or the source and destination do not have corresponding names.
Examples:
// We want to transform the name to something Cocoa-esque
[mapping mapKeyPath:@"created_at" toAttribute:@"createdAt"];
// We want to extract nested data and map it to a property
[mapping mapKeyPath:@"results.metadata.generated_on" toAttribute:@"generationTimestamp"];
See Also
Declared In
RKObjectMapping.h
mapKeyPath:toRelationship:withMapping:
Instantiate and add an RKObjectRelationshipMapping instance targeting a keyPath within the mappable source data to a relationship property on the target object.
- (void)mapKeyPath:(NSString *)sourceKeyPath toRelationship:(NSString *)destinationRelationship withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping
Parameters
- sourceKeyPath
A key-value coding keyPath to fetch the mappable value from
- destinationRelationship
The relationship name to assign the mapped value to
- objectMapping
An object mapping to use when processing the nested objects
Discussion
Used to quickly define mappings where the source value is deeply nested in the mappable data or the source and destination do not have corresponding names.
Examples:
// We want to transform the name to something Cocoa-esque
[mapping mapKeyPath:@"best_friend" toRelationship:@"bestFriend" withObjectMapping:friendMapping];
// We want to extract nested data and map it to a property
[mapping mapKeyPath:@"best_friend.favorite_cat" toRelationship:@"bestFriendsFavoriteCat" withObjectMapping:catMapping];
See Also
Declared In
RKObjectMapping.h
mapKeyPath:toRelationship:withMapping:serialize:
Instantiate and add an RKObjectRelationshipMapping instance targeting a keyPath within the mappable source data to a relationship property on the target object.
- (void)mapKeyPath:(NSString *)relationshipKeyPath toRelationship:(NSString *)keyPath withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping serialize:(BOOL)serialize
Parameters
- serialize
A boolean value indicating whether to include this relationship in serialization
- destinationRelationship
The relationship name to assign the mapped value to
- objectMapping
An object mapping to use when processing the nested objects
- sourceKeyPath
A key-value coding keyPath to fetch the mappable value from
Discussion
Used to indicate whether the relationship should be included in serialization.
Declared In
RKObjectMapping.h
mapKeyPathsToAttributes:
Quickly define a group of attribute mappings using alternating keyPath and attribute names. You must provide an equal number of keyPath and attribute pairs or an exception will be generated.
- (void)mapKeyPathsToAttributes:(NSString *)sourceKeyPath, ...
Parameters
- sourceKeyPath
A key-value coding key path to fetch a mappable value from
- ...
A nil-terminated sequence of strings alternating between source key paths and destination attributes
Discussion
For example:
[personMapping mapKeyPathsToAttributes:@"name", @"name", @"createdAt", @"createdAt", @"street_address", @"streetAddress", nil];
Declared In
RKObjectMapping.h
mapRelationship:withMapping:
Defines a relationship mapping for a key where the source keyPath and the destination relationship property have the same name.
- (void)mapRelationship:(NSString *)relationshipKey withMapping:(RKObjectMappingDefinition *)objectOrDynamicMapping
Parameters
- relationshipKey
A key-value coding key corresponding to a value in the mappable source object and a property
on the destination class that have the same name.
- objectOrDynamicMapping
An RKObjectMapping or RKObjectDynamic mapping to apply when mapping the relationship
Discussion
For example, given the transformation from a JSON dictionary:
{“name”: “My Name”, “age”: 28, “cat”: { “name”: “Asia” } }
To a Person class with corresponding ‘cat’ relationship property, we could configure the mappings via:
RKObjectMapping* catMapping = [RKObjectMapping mappingForClass:[Cat class]];
[personMapping mapRelationship:@"cat" withObjectMapping:catMapping];
Declared In
RKObjectMapping.h
mappableObjectForData:
Returns an auto-released object that can be used to apply this object mapping given a set of mappable data. For transient objects, this generally returns an instance of the objectClass. For Core Data backed persistent objects, mappableData will be inspected to search for primary key data to lookup existing object instances.
- (id)mappableObjectForData:(id)mappableData
Declared In
RKObjectMapping.h
mappingForAttribute:
Returns the attribute mapping targeting the specified attribute on the destination object
- (RKObjectAttributeMapping *)mappingForAttribute:(NSString *)attributeKey
Parameters
- attributeKey
The name of the attribute we want to retrieve the mapping for
Declared In
RKObjectMapping.h
mappingForDestinationKeyPath:
Returns the attribute or relationship mapping for the given destination keyPath.
- (id)mappingForDestinationKeyPath:(NSString *)destinationKeyPath
Parameters
- destinationKeyPath
A keyPath on the destination object that is currently
Declared In
RKObjectMapping.h
mappingForKeyPath:
Returns the attribute or relationship mapping for the given source keyPath.
- (id)mappingForKeyPath:(NSString *)sourceKeyPath
Parameters
- sourceKeyPath
A keyPath within the mappable source object that is mapped to an attribute or relationship in this object mapping.
Declared In
RKObjectMapping.h
mappingForRelationship:
Returns the relationship mapping targeting the specified relationship on the destination object
- (RKObjectRelationshipMapping *)mappingForRelationship:(NSString *)relationshipKey
Parameters
- relationshipKey
The name of the relationship we want to retrieve the mapping for
Declared In
RKObjectMapping.h
mappingForSourceKeyPath:
Returns the attribute or relationship mapping for the given source keyPath.
- (id)mappingForSourceKeyPath:(NSString *)sourceKeyPath
Parameters
- sourceKeyPath
A keyPath within the mappable source object that is mapped to an attribute or relationship in this object mapping.
Declared In
RKObjectMapping.h
removeAllMappings
Removes all currently configured attribute and relationship mappings from the object mapping
- (void)removeAllMappings
Declared In
RKObjectMapping.h
removeMapping:
Removes an instance of an attribute or relationship mapping from the object mapping
- (void)removeMapping:(RKObjectAttributeMapping *)attributeOrRelationshipMapping
Parameters
- attributeOrRelationshipMapping
The attribute or relationship mapping to remove
Declared In
RKObjectMapping.h
removeMappingForKeyPath:
Remove the attribute or relationship mapping for the specified source keyPath
- (void)removeMappingForKeyPath:(NSString *)sourceKeyPath
Parameters
- sourceKeyPath
A key-value coding key path to remove the mappings for
Declared In
RKObjectMapping.h