2014-05-06 19:41:08 +02:00
|
|
|
#import "PropertyListPreferences.h"
|
|
|
|
#import "Constraints.h"
|
2015-08-23 00:00:39 +02:00
|
|
|
#import "TSStorageHeaders.h"
|
2014-11-21 00:51:23 +01:00
|
|
|
|
|
|
|
#define SignalDatabaseCollection @"SignalPreferences"
|
2014-05-06 19:41:08 +02:00
|
|
|
|
2015-03-12 00:46:31 +01:00
|
|
|
|
2014-05-06 19:41:08 +02:00
|
|
|
@implementation PropertyListPreferences
|
|
|
|
|
|
|
|
-(void) clear {
|
|
|
|
@synchronized(self) {
|
2014-09-08 01:31:05 +02:00
|
|
|
NSString *appDomain = NSBundle.mainBundle.bundleIdentifier;
|
|
|
|
[NSUserDefaults.standardUserDefaults removePersistentDomainForName:appDomain];
|
2014-05-06 19:41:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-21 00:51:23 +01:00
|
|
|
- (id)tryGetValueForKey:(NSString *)key {
|
2014-05-06 19:41:08 +02:00
|
|
|
require(key != nil);
|
2014-11-21 00:51:23 +01:00
|
|
|
return [TSStorageManager.sharedManager objectForKey:key inCollection:SignalDatabaseCollection];
|
2014-05-06 19:41:08 +02:00
|
|
|
}
|
2014-11-21 00:51:23 +01:00
|
|
|
- (void)setValueForKey:(NSString *)key toValue:(id)value {
|
2014-05-06 19:41:08 +02:00
|
|
|
require(key != nil);
|
2014-11-21 00:51:23 +01:00
|
|
|
|
|
|
|
[TSStorageManager.sharedManager setObject:value forKey:key inCollection:SignalDatabaseCollection];
|
2014-05-06 19:41:08 +02:00
|
|
|
}
|
2014-11-21 00:51:23 +01:00
|
|
|
- (id)adjustAndTryGetNewValueForKey:(NSString *)key afterAdjuster:(id (^)(id))adjuster {
|
2014-05-06 19:41:08 +02:00
|
|
|
require(key != nil);
|
|
|
|
require(adjuster != nil);
|
|
|
|
@synchronized(self) {
|
|
|
|
id oldValue = [self tryGetValueForKey:key];
|
|
|
|
id newValue = adjuster(oldValue);
|
|
|
|
[self setValueForKey:key toValue:newValue];
|
|
|
|
return newValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|