Instance Method

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.

Declaration

- (instancetype)initWithObjects:(ObjectType  _Nonnull const *)objects forKeys:(id<NSCopying>  _Nonnull const *)keys count:(NSUInteger)cnt;

Parameters

objects

A C array of values for the new dictionary.

keys

A C array of keys for the new dictionary. Each key is copied (using copyWithZone:; keys must conform to the NSCopying protocol), and the copy is added to the new dictionary.

count

The number of elements to use from the keys and objects arrays. count must not exceed the number of elements in objects or 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 a key or value object is nil.

This method is a designated initializer of NSDictionary.

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.

+ dictionaryWithObjectsAndKeys:

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

- 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.