-
Notifications
You must be signed in to change notification settings - Fork 0
/
StepValueTranformer.m
71 lines (57 loc) · 1.27 KB
/
StepValueTranformer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// StepValueTranformer.m
// ModeMaker
//
// Created by David Hirsch on 9/21/09.
// Copyright 2009 Western Washington University. All rights reserved.
//
#import "StepValueTranformer.h"
@implementation StepValueTranformer
+ (Class)transformedValueClass
{
return [NSNumber class];
}
+ (BOOL)allowsReverseTransformation
{
return NO;
}
- (id)init
{
self = [super init];
stepPoint = 0;
inverted = NO;
return self;
}
- (id)initWithValue:(float) inValue
inverted: (BOOL) inInverted;
{
self = [super init];
stepPoint = inValue;
inverted = inInverted;
return self;
}
- (id)transformedValue:(id)value
{
float inputValue;
float outputValue;
if (value == nil) return nil;
// Attempt to get a reasonable value from the
// value object.
if ([value respondsToSelector: @selector(floatValue)]) {
// handles NSString and NSNumber
inputValue = [value floatValue];
} else {
[NSException raise: NSInternalInconsistencyException
format: @"Value (%@) does not respond to -floatValue.",
[value class]];
}
// calculate output value
if (inputValue >= stepPoint)
outputValue = 0;
else
outputValue = 1;
if (inverted)
outputValue = !(outputValue);
return [NSNumber numberWithFloat: outputValue];
}
@end