Skip to content

Commit 887b4a4

Browse files
committed
Added support for configuring objectClass using the class name instead of Class object.
1 parent ddf2cb1 commit 887b4a4

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Code/ObjectMapping/RKObjectMapping.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ relationship. Relationships are processed using an object mapping as well.
5959
*/
6060
@property (nonatomic, assign) Class objectClass;
6161

62+
/**
63+
The name of the target class the receiver defines a mapping for.
64+
65+
@see objectClass
66+
*/
67+
@property (nonatomic, copy) NSString *objectClassName;
68+
6269
/**
6370
The aggregate collection of attribute and relationship mappings within this object mapping
6471
*/
@@ -146,6 +153,14 @@ relationship. Relationships are processed using an object mapping as well.
146153
*/
147154
+ (id)mappingForClass:(Class)objectClass;
148155

156+
/**
157+
Creates and returns an object mapping for the class with the given name
158+
159+
@param objectClassName The name of the class the mapping is for.
160+
@return A new object mapping with for the class with given name.
161+
*/
162+
+ (id)mappingForClassWithName:(NSString *)objectClassName;
163+
149164
/**
150165
Returns an object mapping useful for configuring a serialization mapping. The object
151166
class is configured as NSMutableDictionary

Code/ObjectMapping/RKObjectMapping.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ + (id)mappingForClass:(Class)objectClass {
4545
return [mapping autorelease];
4646
}
4747

48+
+ (id)mappingForClassWithName:(NSString *)objectClassName {
49+
return [self mappingForClass:NSClassFromString(objectClassName)];
50+
}
51+
4852
+ (id)serializationMapping {
4953
return [self mappingForClass:[NSMutableDictionary class]];
5054
}
@@ -120,6 +124,14 @@ - (void)dealloc {
120124
[super dealloc];
121125
}
122126

127+
- (NSString *)objectClassName {
128+
return NSStringFromClass(self.objectClass);
129+
}
130+
131+
- (void)setObjectClassName:(NSString *)objectClassName {
132+
self.objectClass = NSClassFromString(objectClassName);
133+
}
134+
123135
- (NSArray *)mappedKeyPaths {
124136
return [_mappings valueForKey:@"destinationKeyPath"];
125137
}

0 commit comments

Comments
 (0)