mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-10 13:41:48 +08:00
Implementation of Object Mapping 2.0 design:
* Removed RestKit from inheritance hierarchy * Mappings are implemented as concrete classes * Mapper is much more flexible & powerful * Much more robust error handling * Serialization is reimplemented as an object mapping operation * Added ability to serialize to JSON natively * Reworked Core Data integration * Simplified the codebase substantially
This commit is contained in:
47
Code/ObjectMapping/RKObjectAttributeMapping.m
Normal file
47
Code/ObjectMapping/RKObjectAttributeMapping.m
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// RKObjectElementMapping.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 4/30/11.
|
||||
// Copyright 2011 Two Toasters. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKObjectAttributeMapping.h"
|
||||
|
||||
@implementation RKObjectAttributeMapping
|
||||
|
||||
@synthesize sourceKeyPath = _sourceKeyPath;
|
||||
@synthesize destinationKeyPath = _destinationKeyPath;
|
||||
|
||||
/**
|
||||
@private
|
||||
*/
|
||||
- (id)initWithSourceKeyPath:(NSString*)sourceKeyPath andDestinationKeyPath:(NSString*)destinationKeyPath {
|
||||
NSAssert(sourceKeyPath != nil, @"Cannot define an element mapping an element name to map from");
|
||||
NSAssert(destinationKeyPath != nil, @"Cannot define an element mapping without a property to apply the value to");
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_sourceKeyPath = [sourceKeyPath retain];
|
||||
_destinationKeyPath = [destinationKeyPath retain];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[_sourceKeyPath release];
|
||||
[_destinationKeyPath release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString*)description {
|
||||
return [NSString stringWithFormat:@"RKObjectKeyPathMapping: %@ => %@", self.sourceKeyPath, self.destinationKeyPath];
|
||||
}
|
||||
|
||||
+ (RKObjectAttributeMapping*)mappingFromKeyPath:(NSString*)sourceKeyPath toKeyPath:(NSString*)destinationKeyPath {
|
||||
RKObjectAttributeMapping* mapping = [[self alloc] initWithSourceKeyPath:sourceKeyPath andDestinationKeyPath:destinationKeyPath];
|
||||
return [mapping autorelease];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user