Fixes a crash in RKObjectMappingProvider where objectMappingsForClass is called after some dynamic mappings have been registered in the provider. Fixes #342. Thanks to @bjornjonsson

This commit is contained in:
Greg Combs
2011-09-14 20:32:37 -05:00
parent 3006516794
commit a1b2201f2a
2 changed files with 32 additions and 4 deletions

View File

@@ -66,12 +66,14 @@
- (NSArray*)objectMappingsForClass:(Class)theClass {
NSMutableArray* mappings = [NSMutableArray array];
NSArray* mappingsToSearch = [[NSArray arrayWithArray:_objectMappings] arrayByAddingObjectsFromArray:[_mappingsByKeyPath allValues]];
for (RKObjectMapping* objectMapping in mappingsToSearch) {
if (objectMapping.objectClass == theClass && ![mappings containsObject:objectMapping]) {
[mappings addObject:objectMapping];
for (NSObject <RKObjectMappingDefinition> *candidateMapping in mappingsToSearch) {
if (![candidateMapping respondsToSelector:@selector(objectClass)] || [mappings containsObject:candidateMapping])
continue;
Class mappedClass = [candidateMapping performSelector:@selector(objectClass)];
if (mappedClass == theClass) {
[mappings addObject:candidateMapping];
}
}
return [NSArray arrayWithArray:mappings];
}