ftp.nice.ch/Attic/openStep/tools/workspace/TheShelf.0.3.3.sd.tgz#/TheShelf.0.3.3.sd/Source/NSDictionary+MiscDefaultsSupport.rtf

This is NSDictionary+MiscDefaultsSupport.rtf in view mode; [Download] [Up]

paperh18648 margl-907 margr0 margt0 margb0fi0 ri0 ql sb0 f1 fs24 Copyright f3 'e3f1 1997, All Rights Reserved.  

pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 fs16 
fs28 
fs16 
fs28 pard s5 li2116 fi0 ri1007 ql f0 b fs56 NSDictionary 
fs16 





fs56 pard s17 li4888 fi-2771 ri1007 ql tx4888 f1 b0 fs28 fs16 fs28 f0 b fs28 Category Name:	b0 fs28 f1 MiscDefaultsSupport
fs16 s10 fs16 fs28 f0 b fs28 Declared In:	b0 fs28 f1 NSDictionary+MiscDefaultsSupport.h
fs16 
fs28 pard s13 li1360 fi0 ri1007 ql f0 b fs36 fs16 




fs36 Category Description
fs16  pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs28 fs16 fs28 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:
fs16 
fs28 fs16 fs28 NSMutableDictionary* registrationDict = [NSMutableDictionary dictionary];
fs16 
fs28 fs16 fs28 [registrationDict setObject:@"YES" forKey:@"UseTheMiscKit"]; [registrationDict setObject:[NSNumber numberWithInt:42] forKey:@"Don'tPanic"];
fs16 
fs28 fs16 fs28 [[NSUserDefaults standardUserDefaults] registerDefaults:registrationDict];
fs16 
fs28 fs16 fs28 ...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:
fs16 
fs28 fs16 fs28 
fs16 
fs28 fs16 fs28 NSMutableDictionary* registrationDict = [NSMutableDictionary dictionary];
fs16 
fs28 fs16 fs28 [registrationDict setBool:YES forKey:@"UseTheMiscKit"]; [registrationDict setInteger:42 forKey:@"Don'tPanic"];
fs16 
fs28 fs16 fs28 [[NSUserDefaults standardUserDefaults] registerDefaults:registrationDict];
fs16 
fs28 fs16 fs28 
fs16 
fs28 fs16 fs28 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.  
fs16 
fs28 fs16 fs28 b NOTE:b0  We propably should add the keyPath methods to the EOF part for these too.  Could be useful.
fs28s13 li1360 fi0 ri1007 ql f0 b fs36 fs16 




fs36 Method Types
fs16  f1 b0 fs28 s35 li6148 fi-4031 ri1007 ql tx6148 tx9676 tx10180 fs16  fs28 NSUserDefaults-like getters 	{f3 -} stringForKey:
pard s34 li6652 fi-503 ri1007 ql tx9676 tx10180 {f3 -} arrayForKey:
{f3 -} dictionaryForKey:
{f3 -} dataForKey:
{f3 -} stringArrayForKey:
{f3 -} integerForKey:
{f3 -} floatForKey:
{f3 -} boolForKey:
pard s13 li1360 fi0 ri1007 ql f0 b fs36 fs16 




fs36 Instance Methods
fs16  fs36 s21 li2493 fi-1132 fi-376 fs28 fs16 fs29 b arrayForKey:
s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (NSArray *)b arrayForKey:b0 (id)i aKeyi0 b b0 
pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 
fs28 Invokes b objectForKey:b0  with key i aKeyi0 .  Returns the corresponding value if it's some kind of a NSArray object and b nilb0  otherwise. 
fs16 
fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 


fs29 b boolForKey:
s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (BOOL)b boolForKey:b0 (id)i aKeyi0 b b0 
pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 
fs28 Invokes b stringForKey:b0  with key i aKeyi0  and invokes the method b boolValueb0  on the returned object. 
fs16 
fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 


fs29 b dataForKey:
s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (NSData *)b dataForKey:b0 (id)i aKeyi0 b b0 
pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 
fs28 Invokes b objectForKey:b0  with key i aKeyi0 .  Returns the corresponding value if it's some kind of a NSDictionary object and b nilb0  otherwise. 
fs16 
fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 


fs29 b dictionaryForKey:
s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (NSDictionary *)b dictionaryForKey:b0 (id)i aKeyi0 b b0 
pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 
fs28 Invokes b objectForKey:b0  with key i aKeyi0 .  Returns the corresponding value if it's some kind of a NSDictionary object and b nilb0  otherwise. 
fs16 
fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 


fs29 b floatForKey:
s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (float)b floatForKey:b0 (id)i aKeyi0 b b0 
pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 
fs28 Invokes b stringForKey:b0  with key i aKeyi0  and invokes the method b floatValueb0  on the returned object. 
fs16 
fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 


fs29 b integerForKey:
s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (int)b integerForKey:b0 (id)i aKeyi0 b b0 
pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 
fs28 Invokes b stringForKey:b0  with key i aKeyi0  and invokes the method b intValueb0  on the returned object. 
fs16 
fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 


fs29 b stringArrayForKey:
s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (NSArray *)b stringArrayForKey:b0 (id)i aKeyi0 b b0 
pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 
fs28 Invokes arrayForKey: with key i aKeyi0 .  Returns the corresponding value if it's an NSArray object containing NSStrings, and b nilb0  otherwise 
fs16 
fs28 pard s19 li2493 fi-376 ri1007 ql f0 fs28 fs16 


fs29 b stringForKey:
s20 li3249 fi-1132 fi-756 f1 b0 fs28 {f3 -} (NSString *)b stringForKey:b0 (id)i aKeyi0 b b0 
pard s0 li2116 fi0 ri1007 ql tx2494 tx2872 tx3250 fs16 
fs28 Invokes b objectForKey:b0  with key i aKeyi0 .  Returns the corresponding value if it's some kind of a NSString object and b nilb0  otherwise. 
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.