Contents

dictionaryWithObjects:forKeys:

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

Declaration

+ (instancetype) dictionaryWithObjects:(NSArray<id> *) objects forKeys:(NSArray<id<NSCopying>> *) keys;

Parameters

  • 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 Copy(with:); keys must conform to the NSCopying protocol), and the copy is added to the dictionary.

Return Value

A new dictionary containing entries constructed from the contents of objects and keys.

Discussion

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.

See Also

Creating a Dictionary from Objects and Keys