-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeekDays.m
44 lines (36 loc) · 955 Bytes
/
WeekDays.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
//
// WeekDays.m
// Allowance
//
// Created by Pablo Collins on 6/27/10.
//
#import "WeekDays.h"
@implementation WeekDays
+ (NSArray *)names {
static NSArray *names;
if (names == nil) {
names = [[NSArray alloc] initWithObjects:@"Sunday",@"Monday",@"Tuesday",@"Wednesday",@"Thursday",@"Friday",@"Saturday",nil];
}
return names;
}
+ (NSArray *)numbers {
NSMutableArray *a = [[NSMutableArray alloc] initWithCapacity:7];
for (int i = 1; i < 7; i++) {
[a addObject:[NSNumber numberWithInt:i]];
}
return a;
}
+ (NSDictionary *)index {
static NSDictionary *index;
if (index == nil) {
[NSDictionary dictionaryWithObjects:[self names] forKeys:[self numbers]];
}
return index;
}
+ (NSString *)nameForNum:(NSNumber *)n {
return [[self names] objectAtIndex:[n unsignedIntValue]-1];
}
+ (NSNumber *)numForName:(NSString *)name {
return [[self index] objectForKey:name];
}
@end