-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSMRouteSettings.m
59 lines (47 loc) · 1.74 KB
/
SMRouteSettings.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
//
// SMRouteSettings.m
// testRouteMe
//
// Created by Rasko Gojkovic on 6/12/13.
// Copyright (C) 2013 City of Copenhagen.
//
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at
// http://mozilla.org/MPL/2.0/.
//
#import "SMRouteSettings.h"
static NSLock * _sharingLock;
@implementation SMRouteSettings
- (void)loadFromDefaultPlist{
[self loadSettingsFromBundlePlist:DEFAULT_ROUTESETTINGS_FILENAME];
[self loadSettingsFromBundlePlist:[DEFAULT_ROUTESETTINGS_FILENAME stringByAppendingString:DEFAULT_PRIVATE_SUFFIX]];
[self loadSettingsFromBundlePlist:[DEFAULT_ROUTESETTINGS_FILENAME stringByAppendingString:DEFAULT_PRIVATE_APP_SUFFIX]];
}
- (BOOL)loadSettingsFromBundlePlist:(NSString*)fileName{
NSString * filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"plist"];
if(!filePath) return NO;
NSDictionary * dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
NSString * lwKey;
for(NSString * keyStr in dict.allKeys){
lwKey = [keyStr lowercaseString];
//check if getter exist (that should be sufficient for this class)
if([self respondsToSelector:NSSelectorFromString(lwKey)]){
[self setValue:[dict valueForKey:keyStr] forKey:lwKey];
}
}
return YES;
}
+ (void)initialize{
_sharingLock = [NSLock new];
}
+ (SMRouteSettings*)sharedInstance{
static SMRouteSettings * _shared_instance = nil;
[_sharingLock lock];
if(!_shared_instance){
_shared_instance = [SMRouteSettings new];
[_shared_instance loadFromDefaultPlist];
}
[_sharingLock unlock];
return _shared_instance;
}
@end