Changeset 5126
- Timestamp:
- 12/13/07 16:47:21 (7 months ago)
- Files:
-
- WiredAdditions/trunk/WISettings.h (modified) (1 diff)
- WiredAdditions/trunk/WISettings.m (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
WiredAdditions/trunk/WISettings.h
r5011 r5126 30 30 NSString *_identifier; 31 31 id _defaults; 32 NSDictionary *_defaultValues; 32 33 } 33 34 WiredAdditions/trunk/WISettings.m
r5011 r5126 30 30 #import <WiredAdditions/WISettings.h> 31 31 32 static id _WISettingsSharedSettings; 33 32 static WISettings *WISettingsSharedSettings; 34 33 35 34 @interface WISettings(Private) 36 35 37 + (id)_settings; 38 + (id)_settingsWithIdentifier:(NSString *)identifier; 36 + (WISettings *)_settings; 39 37 - (id)_initWithIdentifier:(NSString *)identifier; 40 38 … … 49 47 @implementation WISettings(Private) 50 48 51 + (id)_settings { 52 return [self _settingsWithIdentifier:NULL]; 53 } 54 55 56 57 + (id)_settingsWithIdentifier:(NSString *)identifier { 58 if(!_WISettingsSharedSettings) 59 [self loadWithIdentifier:identifier]; 60 61 return _WISettingsSharedSettings; 49 + (WISettings *)_settings { 50 if(!WISettingsSharedSettings) 51 [self loadWithIdentifier:NULL]; 52 53 return WISettingsSharedSettings; 62 54 } 63 55 … … 65 57 66 58 - (id)_initWithIdentifier:(NSString *)identifier { 67 NSDictionary *defaultValues;68 NSString *key;69 NSEnumerator *enumerator;70 BOOL synchronize = NO;71 id object;72 73 59 self = [super init]; 74 60 … … 80 66 _defaults = [[NSMutableDictionary alloc] init]; 81 67 } else { 82 _defaults = [NSUserDefaults standardUserDefaults];68 _defaults = [NSUserDefaults standardUserDefaults]; 83 69 } 84 70 85 defaultValues = [[self class] defaults]; 86 enumerator = [[defaultValues allKeys] objectEnumerator]; 87 88 while((key = [enumerator nextObject])) { 89 object = [_defaults objectForKey:key]; 90 91 if(!object) { 92 object = [defaultValues objectForKey:key]; 93 94 [_defaults setObject:object forKey:key]; 95 96 synchronize = YES; 97 } 98 } 99 100 if(synchronize) 101 [self _synchronize]; 71 _defaultValues = [[[self class] defaults] retain]; 102 72 103 73 return self; … … 117 87 118 88 - (id)_objectForKey:(id)key { 119 return [_defaults objectForKey:key]; 89 id object; 90 91 object = [_defaults objectForKey:key]; 92 93 if(object) 94 return object; 95 96 return [_defaultValues objectForKey:key]; 120 97 } 121 98 … … 144 121 145 122 + (void)loadWithIdentifier:(NSString *)identifier { 146 if(! _WISettingsSharedSettings)147 _WISettingsSharedSettings = [[self alloc] _initWithIdentifier:identifier];123 if(!WISettingsSharedSettings) 124 WISettingsSharedSettings = [[self alloc] _initWithIdentifier:identifier]; 148 125 } 149 126
