Next: 3.3 Retrieving a value Up: 3 NSDictionary Previous: 3.1 What is it

3.2 Creating a NSDictionary

To create a NSDictionary, you can use the method
+dictionaryWithObjectsAndKeys:
which takes as argument a list of objects (to be considered in couples; the first one is the value, the second is the key); the list is terminated by nil. The following example creates the dictionary used as example in the previous section:
NSDictionary *dict;

dict = [NSDictionary dictionaryWithObjectsAndKeys:
               @"/opt/picture.png", @"Luca", 
               @"/home/nico/birthday.png", @"Birthday Photo", 
               @"/home/nico/birthday.png", @"Birthday Image", 
               @"/home/marghe/pic.jpg", @"My Sister", nil];
Please note the the keys follow their values rather than preceding them.



2008-01-16