-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSWIsNilDate.m
74 lines (58 loc) · 1.39 KB
/
SWIsNilDate.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
72
73
74
//
// SWIsNilDate.m
// This file is part of the "SWApplicationSupport" project, and is distributed under the MIT License.
//
// Created by Samuel Williams on 19/10/05.
// Copyright 2005 Samuel Williams. All rights reserved.
//
#import "SWIsNilDate.h"
@implementation SWIsNilDate
+ (void) initialize {
static BOOL initialized = NO;
if (!initialized) {
[NSValueTransformer setValueTransformer:[[[self class] alloc] init] forName:@"SWIsNilDate"];
initialized = YES;
}
}
+ (Class)transformedValueClass {
return [NSString self];
}
+ (BOOL)allowsReverseTransformation {
return YES;
}
- (id)transformedValue:(id)value {
//NSLog (@"Transforming: %@", value);
return (value == nil) ? nil : @YES;
}
- (id)reverseTransformedValue:(id)value {
//NSLog (@"Reverse Transforming: %@", value);
if (((NSNumber*)value).boolValue)
return [NSDate date];
else
return nil;
}
@end
@implementation SWBlankStringIsNil
+ (void) initialize {
static BOOL initialized = NO;
if (!initialized) {
[NSValueTransformer setValueTransformer:[[[self class] alloc] init] forName:@"SWBlankStringIsNil"];
initialized = YES;
}
}
+ (Class)transformedValueClass {
return [NSString self];
}
+ (BOOL)allowsReverseTransformation {
return YES;
}
- (id)transformedValue:(id)value {
if (value && [value isEqualTo:@""]) {
return nil;
}
return value;
}
- (id)reverseTransformedValue:(id)value {
return value;
}
@end