mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
or before ) or padding at end of line. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20773 72102866-910b-0410-8b05-ffd578937521
40 lines
1.2 KiB
Objective-C
40 lines
1.2 KiB
Objective-C
/* A simple demonstration of the NSDictionary object.
|
|
In this example the NSDictionary holds int's which are keyed by strings. */
|
|
|
|
|
|
#include <Foundation/Foundation.h>
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
#include <Foundation/NSDictionary.h>
|
|
#include <Foundation/NSValue.h>
|
|
#include <Foundation/NSString.h>
|
|
|
|
int
|
|
main()
|
|
{
|
|
NSMutableDictionary *d;
|
|
CREATE_AUTORELEASE_POOL(pool);
|
|
|
|
/* Create a Dictionary object. */
|
|
d = [[NSMutableDictionary alloc] initWithCapacity: 32];
|
|
|
|
/* Load the dictionary with some items */
|
|
[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"];
|
|
|
|
NSLog(@"There are %u elements stored in the dictionary\n", [d count]);
|
|
|
|
NSLog(@"Element %d is stored at \"%s\"\n",
|
|
[[d objectForKey: @"three"] intValue], "three");
|
|
|
|
NSLog(@"Removing element stored at \"three\"\n");
|
|
[d removeObjectForKey: @"three"];
|
|
|
|
NSLog(@"Now there are %u elements stored in the dictionary\n", [d count]);
|
|
|
|
DESTROY(pool);
|
|
exit(0);
|
|
}
|