libs-base/Examples/dictionary.m
mccallum 3a43130da6 Initial revision
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1 72102866-910b-0410-8b05-ffd578937521
1994-11-04 16:29:24 +00:00

40 lines
1 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 <objects/stdobjects.h>
#include <objects/Dictionary.h>
int main()
{
id d;
/* Create a Dictionary object that will store int's with string keys */
d = [[Dictionary alloc]
initWithType:@encode(int)
keyType:@encode(char*)];
/* Load the dictionary with some items */
[d putElement:1 atKey:"one"];
[d putElement:2 atKey:"two"];
[d putElement:3 atKey:"three"];
[d putElement:4 atKey:"four"];
[d putElement:5 atKey:"five"];
[d putElement:6 atKey:"six"];
printf("There are %u elements stored in the dictionary\n",
[d count]);
printf("Element %d is stored at \"%s\"\n",
[d elementAtKey:"three"].int_u, "three");
printf("Removing element stored at \"three\"\n");
[d removeElementAtKey:"three"];
printf("Removing element 2\n");
[d removeElement:2];
printf("Now there are %u elements stored in the dictionary\n",
[d count]);
exit(0);
}