-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathUserDefaults.m
More file actions
192 lines (153 loc) · 4.25 KB
/
Copy pathUserDefaults.m
File metadata and controls
192 lines (153 loc) · 4.25 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//
// UserDefaults.m
// BitStore
//
// Created by Dylan Marriott on 04.02.14.
// Copyright (c) 2014 Dylan Marriott. All rights reserved.
//
#import "UserDefaults.h"
#import "Exchange.h"
#import "Address.h"
#import "ContactList.h"
@implementation UserDefaults {
NSUserDefaults* _defaults;
}
static UserDefaults* sharedInstance;
+ (void)initialize {
[super initialize];
sharedInstance = [[UserDefaults alloc] init];
}
+ (UserDefaults *)instance {
return sharedInstance;
}
- (id)init {
if (self = [super init]) {
_defaults = [NSUserDefaults standardUserDefaults];
}
return self;
}
#pragma mark - Public
// Exchange
- (Exchange *)exchange {
return (Exchange *)[self codableObjectForKey:@"exchange"];
}
- (void)setExchange:(Exchange *)exchange {
[self setCodableObject:exchange forKey:@"exchange"];
}
// Addresses
- (NSArray *)addresses {
return (NSArray *)[self codableObjectForKey:@"addresses_2"];
}
- (void)setAddresses:(NSArray *)addresses {
[self setCodableObject:addresses forKey:@"addresses_2"];
}
// Default Address Index
- (NSInteger)defaultAddressIndex {
return [_defaults integerForKey:@"defaultAddressIndex"];
}
- (void)setDefaultAddressIndex:(NSInteger)defaultAddressIndex {
[_defaults setInteger:defaultAddressIndex forKey:@"defaultAddressIndex"];
[_defaults synchronize];
}
// ContactList
- (ContactList *)contactList {
return (ContactList *)[self codableObjectForKey:@"contactList"];
}
- (void)setContactList:(ContactList *)contactList {
[self setCodableObject:contactList forKey:@"contactList"];
}
// Version
- (NSInteger)version {
return [_defaults integerForKey:@"version"];
}
- (void)setVersion:(NSInteger)version {
[_defaults setInteger:version forKey:@"version"];
[_defaults synchronize];
}
// PushActive
- (BOOL)pushActive {
return [_defaults boolForKey:@"pushActive"];
}
- (void)setPushActive:(BOOL)pushActive {
[_defaults setBool:pushActive forKey:@"pushActive"];
[_defaults synchronize];
}
// DefaultPayMode
- (NSInteger)defaultPayMode {
return [_defaults integerForKey:@"defaultPayMode"];
}
- (void)setDefaultPayMode:(NSInteger)defaultPayMode {
[_defaults setInteger:defaultPayMode forKey:@"defaultPayMode"];
[_defaults synchronize];
}
// TX Cache
- (NSMutableDictionary *)txcache {
return (NSMutableDictionary *)[self codableObjectForKey:@"txcache"];
}
- (void)setTxcache:(NSMutableDictionary *)txcache {
[self setCodableObject:txcache forKey:@"txcache"];
}
// Jobs
- (NSArray *)jobs {
return (NSArray *)[self codableObjectForKey:@"jobs"];
}
- (void)setJobs:(NSArray *)jobs {
[self setCodableObject:jobs forKey:@"jobs"];
}
// UserId
- (NSString *)userId {
return [_defaults stringForKey:@"userId"];
}
- (void)setUserId:(NSString *)userId {
[_defaults setObject:userId forKey:@"userId"];
[_defaults synchronize];
}
// Buy enabled
- (BOOL)buyEnabled {
return [_defaults boolForKey:@"buyEnabled"];
}
- (void)setBuyEnabled:(BOOL)buyEnabled {
[_defaults setBool:buyEnabled forKey:@"buyEnabled"];
[_defaults synchronize];
}
// Buy showed
- (BOOL)buyShowed {
return [_defaults boolForKey:@"buyShowed"];
}
- (void)setBuyShowed:(BOOL)buyShowed {
[_defaults setBool:buyShowed forKey:@"buyShowed"];
[_defaults synchronize];
}
// Buy dismissed
- (BOOL)buyDismissed {
return [_defaults boolForKey:@"buyDismissed"];
}
- (void)setBuyDismissed:(BOOL)buyDismissed {
[_defaults setBool:buyDismissed forKey:@"buyDismissed"];
[_defaults synchronize];
}
// CustomerId
- (NSString *)customerId {
return [_defaults stringForKey:@"customerId"];
}
- (void)setCustomerId:(NSString *)customerId {
[_defaults setObject:customerId forKey:@"customerId"];
[_defaults synchronize];
}
#pragma mark -
- (void)reset {
NSString* domain = [[NSBundle mainBundle] bundleIdentifier];
[_defaults removePersistentDomainForName:domain];
}
#pragma mark - Private
- (void)setCodableObject:(id<NSCoding>)object forKey:(NSString *)key {
NSData* encoded = [NSKeyedArchiver archivedDataWithRootObject:object];
[_defaults setObject:encoded forKey:key];
[_defaults synchronize];
}
- (id<NSCoding>)codableObjectForKey:(NSString *)key {
NSData* encoded = [_defaults objectForKey:key];
id<NSCoding> ret = [NSKeyedUnarchiver unarchiveObjectWithData:encoded];
return ret;
}
@end