diff --git a/EFMapping/NSObject+EFMapping.m b/EFMapping/NSObject+EFMapping.m index 02f4040..bf74da3 100644 --- a/EFMapping/NSObject+EFMapping.m +++ b/EFMapping/NSObject+EFMapping.m @@ -348,7 +348,7 @@ - (BOOL)setValues:(NSDictionary *)values error:(NSError **)error { #pragma mark - Helper methods - (id)transformObject:(id)incomingObject mapping:(EFMapping *)mapping reverse:(BOOL)reverse error:(NSError **)error { - if (mapping.formatter && [incomingObject isKindOfClass:[NSString class]]) { + if (mapping.formatter && !reverse && [incomingObject isKindOfClass:[NSString class]]) { id formattedObject; NSString *errorDescription = nil; if ([mapping.formatter getObjectValue:&formattedObject forString:incomingObject errorDescription:&errorDescription]) { @@ -357,6 +357,10 @@ - (id)transformObject:(id)incomingObject mapping:(EFMapping *)mapping reverse:(B *error = [NSError errorWithDomain:EFMappingErrorDomain code:EFMappingTransformationError userInfo:@{NSLocalizedDescriptionKey: errorDescription}]; incomingObject = nil; } + } else if (mapping.formatter && reverse && [incomingObject isKindOfClass:mapping.internalClass]) { + NSString *formattedString; + formattedString = [mapping.formatter stringForObjectValue:incomingObject]; + incomingObject = formattedString; } if (mapping.transformer) { incomingObject = [mapping.transformer transformedValue:incomingObject];