<!--
{
  "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/dictionaryWithObjectsAndKeys:",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDictionary(cm)dictionaryWithObjectsAndKeys:"
  },
  "title" : "dictionaryWithObjectsAndKeys:"
}
-->

# dictionaryWithObjectsAndKeys:

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

```
+ (instancetype) dictionaryWithObjectsAndKeys:(id) firstObject;
```

## Parameters

`firstObject`

The first value to add to the new dictionary.

## Discussion

After passing `firstObj`, pass a null-terminated list of alternating values and keys as variadic arguments. If any key is `nil`, an [`invalidArgumentException`](/documentation/Foundation/NSExceptionName/invalidArgumentException) is raised.

This method is similar to [`dictionaryWithObjects:forKeys:`](/documentation/Foundation/NSDictionary/dictionaryWithObjects:forKeys:), differing only in the way key-value pairs are specified.

For example:

```objc
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
    @"value1", @"key1", @"value2", @"key2", nil];
```

---

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)