dictionaryWithObjects :forKeys:
Creates and returns a dictionary containing entries constructed from the contents of an array of keys and an array of values.
Parameters of [NSDictionary dictionaryWithObjects]
- objects
- An array containing the values for the new dictionary.
- keys
- An array containing the keys for the new dictionary. Each key is copied (using
copyWithZone:; keys must conform to theNSCopyingprotocol), and the copy is added to the dictionary.
Return Value
A new dictionary containing entries constructed from the contents of objects and keys.
Discussion of [NSDictionary dictionaryWithObjects]
This method steps through the objects and keys arrays, creating entries in the new dictionary as it goes. An
NSInvalidArgumentException is raised if objects and keys don’t have the same number of elements.
Example of [NSDictionary dictionaryWithObjects]
NSArray *keys = [NSArray arrayWithObjects:@"key1", @"key2", nil];
NSArray *objects = [NSArray arrayWithObjects:@"value1", @"value2", nil];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects :objects
forKeys:keys];
Example of [NSDictionary dictionaryWithObjects]
NSDictionary *activeMissions = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects:tiger, bull, peacock, nil] forKeys: [NSArray arrayWithObjects:@tiger, @"bull", @"peacock", nil]];