Added support for configuring objectClass using the class name instead of Class object.

This commit is contained in:
Blake Watters
2012-03-28 19:19:55 -04:00
parent ddf2cb1a79
commit 887b4a4743
2 changed files with 27 additions and 0 deletions

View File

@@ -59,6 +59,13 @@ relationship. Relationships are processed using an object mapping as well.
*/
@property (nonatomic, assign) Class objectClass;
/**
The name of the target class the receiver defines a mapping for.
@see objectClass
*/
@property (nonatomic, copy) NSString *objectClassName;
/**
The aggregate collection of attribute and relationship mappings within this object mapping
*/
@@ -146,6 +153,14 @@ relationship. Relationships are processed using an object mapping as well.
*/
+ (id)mappingForClass:(Class)objectClass;
/**
Creates and returns an object mapping for the class with the given name
@param objectClassName The name of the class the mapping is for.
@return A new object mapping with for the class with given name.
*/
+ (id)mappingForClassWithName:(NSString *)objectClassName;
/**
Returns an object mapping useful for configuring a serialization mapping. The object
class is configured as NSMutableDictionary

View File

@@ -45,6 +45,10 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
return [mapping autorelease];
}
+ (id)mappingForClassWithName:(NSString *)objectClassName {
return [self mappingForClass:NSClassFromString(objectClassName)];
}
+ (id)serializationMapping {
return [self mappingForClass:[NSMutableDictionary class]];
}
@@ -120,6 +124,14 @@ NSString* const RKObjectMappingNestingAttributeKeyName = @"<RK_NESTING_ATTRIBUTE
[super dealloc];
}
- (NSString *)objectClassName {
return NSStringFromClass(self.objectClass);
}
- (void)setObjectClassName:(NSString *)objectClassName {
self.objectClass = NSClassFromString(objectClassName);
}
- (NSArray *)mappedKeyPaths {
return [_mappings valueForKey:@"destinationKeyPath"];
}