This repository was archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNibwarePrefs.m
More file actions
73 lines (57 loc) · 1.75 KB
/
NibwarePrefs.m
File metadata and controls
73 lines (57 loc) · 1.75 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
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
//
// NibwarePrefs.m
// pingle
//
// Created by Robert Sanders on 9/23/08.
// Copyright 2008 ViTrue, Inc.. All rights reserved.
//
#import "Nibware.h"
#import "NibwarePrefs.h"
@implementation NibwarePrefs
@end
@implementation NSUserDefaults (Nibware)
- (void) setValueByParsedString:(NSString *)value forKey:(NSString *)key
{
id current = [self objectForKey:key];
NSString *clazzName = NSStringFromClass([current class]);
NSLog(@"current value for %@ is class %@", key, [value class]);
if ([clazzName isEqualToString:@"NSCFBoolean"]
|| [value isEqualToString:@"t"]
|| [value isEqualToString:@"f"]
|| [value isEqualToString:@"Y"]
|| [value isEqualToString:@"N"]
)
{
NSLog(@"setting boolean to value %d", [value boolValue]);
[self setBool:[value boolValue] forKey:key];
}
else {
[self setObject:value forKey:key];
}
}
- (void) setFromDictionary:(NSDictionary *)dict overwrite:(BOOL)overwrite
{
NSLog(@"NIBWARE: setting preferences from dict %@", dict);
for (NSString *key in [dict keyEnumerator]) {
if (!overwrite && [self objectForKey:key]) {
continue;
}
NSString *val = [dict valueForKey:key];
NSLog(@"setting config for %@ to %@", key, val);
[self setValueByParsedString:val forKey:key];
}
}
- (void) setFromDictionary:(NSDictionary *)dict
{
[self setFromDictionary:dict overwrite:YES];
}
- (void) copyFromDictionary:(NSDictionary*)dict overwrite:(BOOL)overwrite
{
for (NSString *key in [dict keyEnumerator]) {
if (!overwrite && [self objectForKey:key]) {
continue;
}
[self setValue:[dict valueForKey:key] forKey:key];
}
}
@end