Copyright ã1997, All Rights Reserved.  

NSDictionary 

Category Name:	MiscDefaultsSupport
Declared In:	NSDictionary+MiscDefaultsSupport.h

Category Description
 
NSDictionaries are often used in combination with the NSUserDefaults class.  Even if both share some methods...they don't share all of them.  This category is intended to add a set of convenience methods which make both APIs look more similar.  This should make your life litte easier since most apps have a place where they register their defualts like this:

NSMutableDictionary* registrationDict = [NSMutableDictionary dictionary];

[registrationDict setObject:@"YES" forKey:@"UseTheMiscKit"]; [registrationDict setObject:[NSNumber numberWithInt:42] forKey:@"Don'tPanic"];

[[NSUserDefaults standardUserDefaults] registerDefaults:registrationDict];

...which looks a littel odd and is somehow confusing since NSUserDefaults usually is handling this sort of thing in a more elegant way.  With this category you can now rewrite your code so that it look more natural:

NSMutableDictionary* registrationDict = [NSMutableDictionary dictionary];

[registrationDict setBool:YES forKey:@"UseTheMiscKit"]; [registrationDict setInteger:42 forKey:@"Don'tPanic"];

[[NSUserDefaults standardUserDefaults] registerDefaults:registrationDict];

While we could have implemented smarter methods we have sticked to the API definitions of the NSUserDefaults classs since otherwise it would become less obviouse while certain code works for NSDictionaries but not for NSUserDefaults.  Time will tell if we should stick with this decission or not.  

NOTE: We propably should add the keyPath methods to the EOF part for these too.  Could be useful.

Method Types
 
 NSUserDefaults-like getters 	- stringForKey:
- arrayForKey:
- dictionaryForKey:
- dataForKey:
- stringArrayForKey:
- integerForKey:
- floatForKey:
- boolForKey:

Instance Methods
 
arrayForKey:
- (NSArray *)arrayForKey:(id)aKey

Invokes objectForKey: with key aKey.  Returns the corresponding value if it's some kind of a NSArray object and nil otherwise. 

boolForKey:
- (BOOL)boolForKey:(id)aKey

Invokes stringForKey: with key aKey and invokes the method boolValue on the returned object. 

dataForKey:
- (NSData *)dataForKey:(id)aKey

Invokes objectForKey: with key aKey.  Returns the corresponding value if it's some kind of a NSDictionary object and nil otherwise. 

dictionaryForKey:
- (NSDictionary *)dictionaryForKey:(id)aKey

Invokes objectForKey: with key aKey.  Returns the corresponding value if it's some kind of a NSDictionary object and nil otherwise. 

floatForKey:
- (float)floatForKey:(id)aKey

Invokes stringForKey: with key aKey and invokes the method floatValue on the returned object. 

integerForKey:
- (int)integerForKey:(id)aKey

Invokes stringForKey: with key aKey and invokes the method intValue on the returned object. 

stringArrayForKey:
- (NSArray *)stringArrayForKey:(id)aKey

Invokes arrayForKey: with key aKey.  Returns the corresponding value if it's an NSArray object containing NSStrings, and nil otherwise 

stringForKey:
- (NSString *)stringForKey:(id)aKey

Invokes objectForKey: with key aKey.  Returns the corresponding value if it's some kind of a NSString object and nil otherwise.