summaryrefslogtreecommitdiffabout
path: root/pumpkin/NumberTransformer.m
Side-by-side diff
Diffstat (limited to 'pumpkin/NumberTransformer.m') (more/less context) (ignore whitespace changes)
-rw-r--r--pumpkin/NumberTransformer.m19
1 files changed, 19 insertions, 0 deletions
diff --git a/pumpkin/NumberTransformer.m b/pumpkin/NumberTransformer.m
new file mode 100644
index 0000000..c02cd8b
--- a/dev/null
+++ b/pumpkin/NumberTransformer.m
@@ -0,0 +1,19 @@
+
+#import "NumberTransformer.h"
+
+@implementation NumberTransformer
+
++(Class)transformedValueClass { return [NSNumber class]; }
++(BOOL)allowsReverseTransformation { return YES; }
+-(id)transformedValue:(id)value {
+ if(value==nil) return nil;
+ if(![value respondsToSelector:@selector(integerValue)]) return nil;
+ return [NSString stringWithFormat:@"%lu",[value integerValue]];
+}
+-(id)reverseTransformedValue:(id)value {
+ if(value==nil) return nil;
+ if(![value respondsToSelector:@selector(integerValue)]) return nil;
+ return @([value integerValue]);
+}
+
+@end