---
title: "dictionaryWithObjects:forKeys:"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsdictionary/dictionarywithobjects:forkeys:"
---

# dictionaryWithObjects:forKeys:

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

## Declaration

```occ
+ (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 doc://com.apple.foundation/documentation/Foundation/NSCopying/copy(with:); keys must conform to the NSCopying protocol), and the copy is added to the dictionary.

## Return Value

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

## Discussion

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

- [dictionaryWithObjects:forKeys:count:](foundation/nsdictionary/dictionarywithobjects:forkeys:count:.md)
- [init(objects:forKeys:)](foundation/nsdictionary/init(objects:forkeys:).md)
- [init(objects:forKeys:count:)](foundation/nsdictionary/init(objects:forkeys:count:).md)
- [dictionaryWithObjectsAndKeys:](foundation/nsdictionary/dictionarywithobjectsandkeys:.md)
- [initWithObjectsAndKeys:](foundation/nsdictionary/initwithobjectsandkeys:.md)
- [init(object:forKey:)](foundation/nsdictionary/init(object:forkey:).md)
