Skip to content

Commit

Permalink
Merge pull request #4 from ijansch/master
Browse files Browse the repository at this point in the history
Make formatters work both ways
  • Loading branch information
johankool committed Mar 31, 2014
2 parents 162b0cf + dc4b289 commit ac05c72
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion EFMapping/NSObject+EFMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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];
Expand Down

0 comments on commit ac05c72

Please sign in to comment.