<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDictionary/dictionaryWithObjects:forKeys:",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDictionary(cm)dictionaryWithObjects:forKeys:"
  },
  "title" : "dictionaryWithObjects:forKeys:"
}
-->

# dictionaryWithObjects:forKeys:

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

```
+ (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:)`](/documentation/Foundation/NSCopying/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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)