2000-06-20 15:18:23 +00:00
|
|
|
/* A simple demonstration of the NSDictionary object.
|
|
|
|
In this example the NSDictionary holds int's which are keyed by strings. */
|
1994-11-04 16:29:24 +00:00
|
|
|
|
2000-06-20 15:18:23 +00:00
|
|
|
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
1996-07-15 18:41:44 +00:00
|
|
|
#include <Foundation/NSValue.h>
|
|
|
|
#include <Foundation/NSString.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
|
2000-06-20 15:18:23 +00:00
|
|
|
int
|
|
|
|
main()
|
1994-11-04 16:29:24 +00:00
|
|
|
{
|
2000-06-20 15:18:23 +00:00
|
|
|
NSMutableDictionary *d;
|
|
|
|
CREATE_AUTORELEASE_POOL(pool);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
1996-07-15 18:41:44 +00:00
|
|
|
/* Create a Dictionary object. */
|
2000-06-20 15:18:23 +00:00
|
|
|
d = [[NSMutableDictionary alloc] initWithCapacity: 32];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Load the dictionary with some items */
|
2000-06-20 15:18:23 +00:00
|
|
|
[d setObject: [NSNumber numberWithInt: 1] forKey: @"one"];
|
|
|
|
[d setObject: [NSNumber numberWithInt: 2] forKey: @"two"];
|
|
|
|
[d setObject: [NSNumber numberWithInt: 3] forKey: @"three"];
|
|
|
|
[d setObject: [NSNumber numberWithInt: 4] forKey: @"four"];
|
|
|
|
[d setObject: [NSNumber numberWithInt: 5] forKey: @"five"];
|
|
|
|
[d setObject: [NSNumber numberWithInt: 6] forKey: @"six"];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-06-20 15:18:23 +00:00
|
|
|
NSLog(@"There are %u elements stored in the dictionary\n", [d count]);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
2005-02-22 11:22:44 +00:00
|
|
|
NSLog(@"Element %d is stored at \"%s\"\n",
|
2000-06-20 15:18:23 +00:00
|
|
|
[[d objectForKey: @"three"] intValue], "three");
|
1994-11-04 16:29:24 +00:00
|
|
|
|
2000-06-20 15:18:23 +00:00
|
|
|
NSLog(@"Removing element stored at \"three\"\n");
|
|
|
|
[d removeObjectForKey: @"three"];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
2000-06-20 15:18:23 +00:00
|
|
|
NSLog(@"Now there are %u elements stored in the dictionary\n", [d count]);
|
1994-11-04 16:29:24 +00:00
|
|
|
|
2000-06-20 15:18:23 +00:00
|
|
|
DESTROY(pool);
|
1994-11-04 16:29:24 +00:00
|
|
|
exit(0);
|
|
|
|
}
|