-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUMMPUserDefaults.m
131 lines (108 loc) · 3.31 KB
/
UMMPUserDefaults.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// UMMPUserDefaults.m
// UMMPerfusion
//
// Created by UMMPerfusion on 06.06.12.
// Copyright (c) 2012, Marcel Reich & Sven Kaiser & Markus Daab & Patrick Schülein & Engin Aslan
// All rights reserved.
//
#import "UMMPUserDefaults.h"
@implementation UMMPUserDefaults
-(id)init {
self = [super init];
//_dictionary = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:[[NSBundle bundleForClass:[self class]] bundleIdentifier]] mutableCopy];
//if (!_dictionary)
_dictionary = [[NSMutableDictionary alloc] init];
//_osirixDefaults= [NSUserDefaults standardUserDefaults];
//NSLog(@"FULL32BITPIPELINE: %@", [_osirixDefaults valueForKey:@"FULL32BITPIPELINE"]);
return self;
}
-(void)dealloc {
[_dictionary release]; _dictionary = NULL;
[super dealloc];
}
-(void)save {
[[NSUserDefaults standardUserDefaults] setPersistentDomain:_dictionary forName:[[NSBundle bundleForClass:[self class]] bundleIdentifier]];
}
-(BOOL)keyExists:(NSString*)key {
return [_dictionary valueForKey:key] != NULL;
}
-(BOOL)bool:(NSString*)key otherwise:(BOOL)otherwise {
NSNumber* value = [_dictionary valueForKey:key];
if (value)
return [value boolValue];
return otherwise;
}
-(void)setBool:(BOOL)value forKey:(NSString*)key {
[_dictionary setValue:[NSNumber numberWithBool:value] forKey:key];
[self save];
}
-(int)int:(NSString*)key otherwise:(int)otherwise {
NSNumber* value = [_dictionary valueForKey:key];
if (value)
return [value intValue];
return otherwise;
}
-(void)setInt:(int)value forKey:(NSString*)key {
[_dictionary setValue:[NSNumber numberWithInt: value] forKey:key];
[self save];
}
-(float)float:(NSString*)key otherwise:(float)otherwise {
NSNumber* value = [_dictionary valueForKey:key];
if (value)
return [value floatValue];
return otherwise;
}
-(void)setFloat:(float)value forKey:(NSString*)key {
[_dictionary setValue:[NSNumber numberWithFloat:value] forKey:key];
[self save];
}
-(void)setString:(NSString*)string forKey:(NSString*)key {
[_dictionary setValue:[NSString stringWithString:string] forKey:key];
[self save];
}
-(NSString*)string:(NSString*)key otherwise:(NSString*)otherwise {
if ([_dictionary valueForKey:key]) {
return [_dictionary valueForKey:key];
}
return otherwise;
}
-(id)obj:(NSString*)key otherwise:(id)otherwise {
if ([_dictionary valueForKey:key]) {
return [_dictionary valueForKey:key];
}
return otherwise;
}
-(void)setObj:(id)data forKey:(NSString*)key {
[_dictionary setValue:data forKey:key];
[self save];
}
//-(NSColor*)color:(NSString*)key otherwise:(NSColor*)otherwise {
// NSData* value = [_dictionary valueForKey:key];
// if (value)
// return [NSUnarchiver unarchiveObjectWithData:value];
// return otherwise;
//}
//
//-(void)setColor:(NSColor*)value forKey:(NSString*)key {
// [_dictionary setValue:[NSArchiver archivedDataWithRootObject:value] forKey:key];
// [self save];
//}
//
//-(NSRect)rect:(NSString*)key otherwise:(NSRect)otherwise {
// NSData* value = [_dictionary valueForKey:key];
// if (value) {
// NSRect temp;
// [value getBytes:&temp length:sizeof(NSRect)];
// return temp;
// }
// return otherwise;
//}
//
//-(void)setRect:(NSRect)value forKey:(NSString*)key {
// NSMutableData* data = [NSMutableData dataWithCapacity:32];
// [data appendBytes:&value length:sizeof(NSRect)];
// [_dictionary setValue:data forKey:key];
// [self save];
//}
@end