Type Method

dictionaryWithObjectsAndKeys:

Creates a dictionary containing entries constructed from the specified set of values and keys.

Declaration

+ (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ...;

Parameters

firstObj

The first value to add to the new dictionary.

...

First the key for firstObj, then a null-terminated list of alternating values and keys. If any key is nil, an NSInvalidArgumentException is raised.

Discussion

This method is similar to dictionaryWithObjects:forKeys:, differing only in the way key-value pairs are specified.

For example:

NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
    @"value1", @"key1", @"value2", @"key2", nil];

See Also

Creating a Dictionary from Objects and Keys

+ dictionaryWithObjects:forKeys:

Creates a dictionary containing entries constructed from the contents of an array of keys and an array of values.

+ dictionaryWithObjects:forKeys:count:

Creates a dictionary containing a specified number of objects from a C array.

- initWithObjects:forKeys:

Initializes a newly allocated dictionary with key-value pairs constructed from the provided arrays of keys and objects.

- initWithObjects:forKeys:count:

Initializes a newly allocated dictionary with the specified number of key-value pairs constructed from the provided C arrays of keys and objects.

- initWithObjectsAndKeys:

Initializes a newly allocated dictionary with entries constructed from the specified set of values and keys.

+ dictionaryWithObject:forKey:

Creates a dictionary containing a given key and value.