37 BOOL _appliesImmediately;
51 if (
self = [super
init])
56 _defaults = someDefaults;
57 _initialValues = [initialValues
copy];
58 _appliesImmediately = YES;
59 _valueProxy = [[_CPUserDefaultsControllerProxy alloc] initWithController:self];
72 return [_valueProxy hasUnappliedChanges];
75 - (void)save:(
id)sender
80 - (void)revert:(
id)sender
85 - (void)revertToInitialValues:(
id)sender
87 [_valueProxy revertToInitialValues];
106 [
CPException raise:CPUnsupportedMethodException
reason:@"decoding of non-shared CPUserDefaultsController not implemented"];
118 [aCoder encodeBool:YES forKey:CPUserDefaultsControllerSharedKey];
122 [
CPException raise:CPUnsupportedMethodException
reason:@"encoding of non-shared CPUserDefaultsController not implemented"];
128 @implementation _CPUserDefaultsControllerProxy :
CPObject 137 if (
self = [super
init])
139 _controller = aController;
157 var value = [_cachedValues objectForKey:aKey];
160 value = [[_controller defaults] objectForKey:aKey];
162 value = [[_controller initialValues] objectForKey:aKey];
165 [_cachedValues setObject:value forKey:aKey];
170 - (void)setValue:(
id)aValue forKey:(
CPString)aKey
173 [_cachedValues setObject:aValue forKey:aKey];
175 [[_controller defaults] setObject:aValue forKey:aKey];
182 var keys = [_cachedValues allKeys],
183 keysCount = [keys count];
187 var key = keys[keysCount];
189 [_cachedValues removeObjectForKey:key];
196 var keys = [_cachedValues allKeys],
197 keysCount = [keys count];
201 var key = keys[keysCount];
202 [[_controller defaults] setObject:[_cachedValues objectForKey:key] forKey:key];
206 - (void)revertToInitialValues
208 var initial = [_controller initialValues],
209 keys = [_cachedValues allKeys],
210 keysCount = [keys count];
214 var key = keys[keysCount];
217 var initialValue = [initial objectForKey:key];
218 if (initialValue !== nil)
219 [_cachedValues setObject:initialValue forKey:key];
221 [_cachedValues removeObjectForKey:key];
230 var
defaults = [_controller defaults],
231 keys = [_cachedValues allKeys],
232 keysCount = [keys count];
236 var key = keys[keysCount],
237 value = [_cachedValues objectForKey:key],
238 newValue = [defaults objectForKey:key];
243 [_cachedValues setObject:newValue forKey:key];
251 var
defaults = [_controller defaults],
252 keys = [_cachedValues allKeys],
253 keysCount = [keys count];
257 var key = keys[keysCount],
258 value = [_cachedValues objectForKey:key],
259 newValue = [defaults objectForKey:key];
286 return _initialValues;
294 _initialValues = aValue;
302 return _appliesImmediately;
308 - (void)setAppliesImmediately:(BOOL)aValue
310 _appliesImmediately = aValue;
Used to implement exception handling (creating & raising).
void encodeWithCoder:(CPCoder aCoder)
void willChangeValueForKey:(CPString aKey)
void removeObserver:(id anObserver)
void addObserver:selector:name:object:(id anObserver, [selector] SEL aSelector, [name] CPString aNotificationName, [object] id anObject)
BOOL appliesImmediately()
void raise:reason:(CPString aName, [reason] CPString aReason)
id initWithDefaults:initialValues:(CPUserDefaults someDefaults, [initialValues] CPDictionary initialValues)
CPNotificationCenter defaultCenter()
A mutable key-value pair collection.
id standardUserDefaults()
id initWithCoder:(CPCoder aDecoder)
id sharedUserDefaultsController()
An immutable string (collection of characters).
BOOL hasUnappliedChanges()
CPUserDefaultsDidChangeNotification
var CPUserDefaultsControllerSharedKey
A notification that can be posted to a CPNotificationCenter.
void didChangeValueForKey:(CPString aKey)
Defines methods for use when archiving & restoring (enc/decoding).
CPUserDefaults defaults()
Sends messages (CPNotification) between objects.
global CPUserDefaultsDidChangeNotification var SharedUserDefaultsController