NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [dict setObject:@"John" forKey:@"Firstname"]; [dict setObject:@"Doe" forKey:@"Lastname"]; [dict setObject:@"info at objectgraph.com" forKey:@"Email"]; NSLog(@"%@", dict); NSArray *keys = [dict allKeys]; // values in foreach loop for (NSString *key in keys) { NSLog(@"%@ is %@",key, [dict objectForKey:key]); }
A collection of example source codes for c/c++ and ios and android platform. It also includes objective c.
Friday, May 6, 2011
NSMutableArray example
Here is a simple example to add elements in a NSMutableDictionary object and go through a for loop to extract values by keys and make sure to release it whenever you finish using it. Note that NSDictionary is readonly. You should create NSMutableDictionary if you want to change the content of the dictionary.