summaryrefslogtreecommitdiffabout
path: root/pumpkin/NSPortNumberTransformer.m
Side-by-side diff
Diffstat (limited to 'pumpkin/NSPortNumberTransformer.m') (more/less context) (ignore whitespace changes)
-rw-r--r--pumpkin/NSPortNumberTransformer.m22
1 files changed, 22 insertions, 0 deletions
diff --git a/pumpkin/NSPortNumberTransformer.m b/pumpkin/NSPortNumberTransformer.m
new file mode 100644
index 0000000..e1a14a5
--- a/dev/null
+++ b/pumpkin/NSPortNumberTransformer.m
@@ -0,0 +1,22 @@
+#import "NSPortNumberTransformer.h"
+
+@implementation NSPortNumberTransformer
+
++(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;
+ NSInteger rv = [value integerValue];
+ if(rv<1 || rv>32767) return nil;
+ return [NSString stringWithFormat:@"%u",rv];
+}
+-(id)reverseTransformedValue:(id)value {
+ if(value==nil) return nil;
+ if(![value respondsToSelector:@selector(integerValue)]) return nil;
+ NSInteger rv = [value integerValue];
+ if(rv<1 || rv>32767) return nil;
+ return [NSNumber numberWithInteger:rv];
+}
+
+@end