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

# initWithObjectsAndKeys:

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

```
- (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`](/documentation/Foundation/NSExceptionName/invalidArgumentException) is raised.

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

For example:

```objc
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
    @"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)