mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 10:11:03 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1650 72102866-910b-0410-8b05-ffd578937521
40 lines
1.2 KiB
Objective-C
40 lines
1.2 KiB
Objective-C
/* A simple demonstration of the GNU Dictionary object.
|
|
In this example the Dictionary holds int's which are keyed by strings. */
|
|
|
|
#include <gnustep/base/Dictionary.h>
|
|
#include <Foundation/NSValue.h>
|
|
#include <Foundation/NSString.h>
|
|
|
|
int main()
|
|
{
|
|
id d;
|
|
|
|
/* Create a Dictionary object. */
|
|
d = [[Dictionary alloc] initWithCapacity: 32];
|
|
|
|
/* Load the dictionary with some items */
|
|
[d putObject: [NSNumber numberWithInt: 1] atKey: @"one"];
|
|
[d putObject: [NSNumber numberWithInt: 2] atKey: @"two"];
|
|
[d putObject: [NSNumber numberWithInt: 3] atKey: @"three"];
|
|
[d putObject: [NSNumber numberWithInt: 4] atKey: @"four"];
|
|
[d putObject: [NSNumber numberWithInt: 5] atKey: @"five"];
|
|
[d putObject: [NSNumber numberWithInt: 6] atKey: @"six"];
|
|
|
|
printf("There are %u elements stored in the dictionary\n",
|
|
[d count]);
|
|
|
|
printf("Element %d is stored at \"%s\"\n",
|
|
[[d objectAtKey: @"three"] intValue],
|
|
"three");
|
|
|
|
printf("Removing element stored at \"three\"\n");
|
|
[d removeObjectAtKey: @"three"];
|
|
|
|
printf("Removing element 2\n");
|
|
[d removeObject: [NSNumber numberWithInt: 2]];
|
|
|
|
printf("Now there are %u elements stored in the dictionary\n",
|
|
[d count]);
|
|
|
|
exit(0);
|
|
}
|