forked from ryanbriones/focus-timer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFTSavedTimerDescriptionTransformer.m
More file actions
40 lines (31 loc) · 1.33 KB
/
FTSavedTimerDescriptionTransformer.m
File metadata and controls
40 lines (31 loc) · 1.33 KB
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
//
// FTSavedTimerDescriptionTransformer.m
// focus-timer
//
// Created by Ryan Carmelo Briones on 5/6/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "FTSavedTimerDescriptionTransformer.h"
#import "FTTimerFormatter.h"
@implementation FTSavedTimerDescriptionTransformer
+ (Class) transformedValueClass { return [NSArray class]; }
+ (BOOL) allowsReverseTransformation { return NO; }
- (id) transformedValue: (id) value {
if(value == nil) return nil;
NSMutableArray *newValue = [NSMutableArray array];
FTTimerFormatter *tf = [[FTTimerFormatter alloc] init];
if([value respondsToSelector: @selector(objectEnumerator)]) {
NSEnumerator *timerEnum = [value objectEnumerator];
NSDictionary *currentTimer;
while(currentTimer = [timerEnum nextObject]) {
NSString *workTimer = [tf stringForObjectValue: [currentTimer objectForKey: @"workSeconds"]];
NSString *breakTimer = [tf stringForObjectValue: [currentTimer objectForKey: @"breakSeconds"]];
[newValue addObject: [NSString stringWithFormat: @"%@ -- %@|%@|%@",
[currentTimer objectForKey: @"name"], workTimer, breakTimer, [currentTimer objectForKey: @"cycles"]]];
}
} else {
[NSException raise: NSInternalInconsistencyException format: @"Value (%@) does not respond to -objectForKey.", [value class]];
}
return newValue;
}
@end