mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-01 22:42:51 +08:00
* 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
56 lines
1.5 KiB
Objective-C
56 lines
1.5 KiB
Objective-C
//
|
|
// RKStaticObjectMappingProvider.m
|
|
// RestKit
|
|
//
|
|
// Created by Jeremy Ellison on 5/6/11.
|
|
// Copyright 2011 Two Toasters. All rights reserved.
|
|
//
|
|
|
|
#import "RKObjectMappingProvider.h"
|
|
|
|
@implementation RKObjectMappingProvider
|
|
|
|
- (id)init {
|
|
if ((self = [super init])) {
|
|
_mappings = [NSMutableDictionary new];
|
|
_serializationMappings = [NSMutableDictionary new];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)dealloc {
|
|
[_mappings release];
|
|
[_serializationMappings release];
|
|
[super dealloc];
|
|
}
|
|
|
|
- (RKObjectMapping*)objectMappingForKeyPath:(NSString*)keyPath {
|
|
return [_mappings objectForKey:keyPath];
|
|
}
|
|
|
|
- (void)setMapping:(RKObjectMapping*)mapping forKeyPath:(NSString*)keyPath {
|
|
[_mappings setValue:mapping forKey:keyPath];
|
|
}
|
|
|
|
- (void)setSerializationMapping:(RKObjectMapping *)mapping forClass:(Class)objectClass {
|
|
[_serializationMappings setValue:mapping forKey:NSStringFromClass(objectClass)];
|
|
}
|
|
|
|
- (RKObjectMapping*)serializationMappingForClass:(Class)objectClass {
|
|
return (RKObjectMapping*)[_serializationMappings objectForKey:NSStringFromClass(objectClass)];
|
|
}
|
|
|
|
- (NSDictionary*)objectMappingsByKeyPath {
|
|
return _mappings;
|
|
}
|
|
|
|
- (void)registerMapping:(RKObjectMapping*)objectMapping withRootKeyPath:(NSString*)keyPath {
|
|
// TODO: Should generate logs
|
|
[self setMapping:objectMapping forKeyPath:keyPath];
|
|
RKObjectMapping* inverseMapping = [objectMapping inverseMapping];
|
|
inverseMapping.rootKeyPath = keyPath;
|
|
[self setSerializationMapping:inverseMapping forClass:objectMapping.objectClass];
|
|
}
|
|
|
|
@end
|