mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-05-13 11:58:17 +08:00
Introduce RKPropertyMapping abstract superclass for RKAttributeMapping and RKRelationshipMapping.
Add primitives for working with attribute, relationship, and property mapping objects.
This commit is contained in:
@@ -19,39 +19,32 @@
|
||||
//
|
||||
|
||||
#import "RKRelationshipMapping.h"
|
||||
#import "RKMapping.h"
|
||||
|
||||
@interface RKRelationshipMapping ()
|
||||
@property (nonatomic, strong, readwrite) NSString *sourceKeyPath;
|
||||
@property (nonatomic, strong, readwrite) NSString *destinationKeyPath;
|
||||
@property (nonatomic, strong, readwrite) RKMapping *mapping;
|
||||
@end
|
||||
|
||||
@implementation RKRelationshipMapping
|
||||
|
||||
@synthesize mapping = _mapping;
|
||||
@synthesize reversible = _reversible;
|
||||
|
||||
+ (RKRelationshipMapping *)mappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(id)objectOrDynamicMapping reversible:(BOOL)reversible
|
||||
+ (RKRelationshipMapping *)relationshipMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(RKMapping *)mapping
|
||||
{
|
||||
RKRelationshipMapping *relationshipMapping = (RKRelationshipMapping *)[self mappingFromKeyPath:sourceKeyPath toKeyPath:destinationKeyPath];
|
||||
relationshipMapping.reversible = reversible;
|
||||
relationshipMapping.mapping = objectOrDynamicMapping;
|
||||
RKRelationshipMapping *relationshipMapping = [self new];
|
||||
relationshipMapping.sourceKeyPath = sourceKeyPath;
|
||||
relationshipMapping.destinationKeyPath = destinationKeyPath;
|
||||
relationshipMapping.mapping = mapping;
|
||||
return relationshipMapping;
|
||||
}
|
||||
|
||||
+ (RKRelationshipMapping *)mappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(id)objectOrDynamicMapping
|
||||
{
|
||||
return [self mappingFromKeyPath:sourceKeyPath toKeyPath:destinationKeyPath withMapping:objectOrDynamicMapping reversible:YES];
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone
|
||||
{
|
||||
RKRelationshipMapping *copy = [super copyWithZone:zone];
|
||||
copy.mapping = self.mapping;
|
||||
copy.reversible = self.reversible;
|
||||
return copy;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_mapping release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (BOOL)isEqualToMapping:(RKRelationshipMapping *)otherMapping
|
||||
{
|
||||
if (! [otherMapping isMemberOfClass:[RKRelationshipMapping class]]) return NO;
|
||||
|
||||
Reference in New Issue
Block a user