Contents

initWithObjectsAndKeys:

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

Declaration

- (instancetype) initWithObjectsAndKeys:(id) firstObject;

Parameters

  • firstObject:

    The first value to add to the new dictionary.

Discussion

After the firstObject value, pass the key for firstObject, then a null-terminated list of alternating values and keys. If any key is nil, an invalidArgumentException is raised.

This method is similar to init(objects:forKeys:), differing only in the way in which the key-value pairs are specified.

For example:

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

See Also

Creating a Dictionary from Objects and Keys