Next: Retrieving a value with Up: NSDictionary Previous: What is it

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.



Nicola 2002-01-13