mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-20 15:44:21 +08:00
Added Object Mapping block helpers to RKObjectManager and RKObjectMapping. These enable you to perform ad-hoc object mapping very easily. Extended RKObjectRouter to match on superclasses if no specific route is found. This is helpful when using mocked objects with frameworks like Kiwi. fixes #238
This commit is contained in:
@@ -123,6 +123,53 @@ relationship. Relationships are processed using an object mapping as well.
|
||||
*/
|
||||
+ (id)mappingForClass:(Class)objectClass;
|
||||
|
||||
/**
|
||||
Returns an object mapping useful for configuring a serialization mapping. The object
|
||||
class is configured as NSMutableDictionary
|
||||
*/
|
||||
+ (id)serializationMapping;
|
||||
|
||||
#if NS_BLOCKS_AVAILABLE
|
||||
/**
|
||||
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.
|
||||
|
||||
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 delegate:self block:^(RKObjectLoader* loader) {
|
||||
loader.objectMapping = [RKObjectMapping mappingForClass:[Person class] block:^(RKObjectMapping* mapping) {
|
||||
[mapping mapAttributes:@"email", @"first_name", nil];
|
||||
}];
|
||||
}];
|
||||
*/
|
||||
+ (id)mappingForClass:(Class)objectClass block:(void(^)(RKObjectMapping*))block;
|
||||
|
||||
/**
|
||||
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.
|
||||
|
||||
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 serializationMappingWithBlock:^(RKObjectMapping* mapping) {
|
||||
[mapping mapAttributes:@"password", nil];
|
||||
}];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
Using the block forms we are able to quickly configure and send this request on the fly.
|
||||
*/
|
||||
+ (id)serializationMappingWithBlock:(void(^)(RKObjectMapping*))block;
|
||||
#endif
|
||||
|
||||
/**
|
||||
Add a configured attribute mapping to this object mapping
|
||||
|
||||
|
||||
Reference in New Issue
Block a user