Friday, May 6, 2011

Another example of NSMutableDictionary with NSEnumerator

Another example of NSMutableDictionary object manipulation with NSEnumerator interface. The object is created and initialized by three key-value pairs, then keyEnumerator method is called to create NSEnumerator object for the NSMutableDictionary object.


NSMutableDictionary *myDictionary = [[ NSMutableDictionary alloc]
init];
    [ myDictionary setObject:@"Keith" forKey:@"name"];
    [ myDictionary setObject:@"hacker" forKey:@"subject"];
    [ myDictionary setObject:@"4/9/2002" forKey:@"date"];

    NSEnumerator *enumerator = [ myDictionary keyEnumerator];
    NSString *key;
    while (key = [ enumerator nextObject]) {
        printf("%s\n", [[ myDictionary objectForKey:key] UTF8String]);
    }