<!--
{
  "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/init(objects:forKeys:count:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDictionary(im)initWithObjects:forKeys:count:"
  },
  "title" : "init(objects:forKeys:count:)"
}
-->

# init(objects:forKeys:count:)

Initializes a newly allocated dictionary with the specified number of key-value pairs constructed from the provided C arrays of keys and objects.

```
init(objects: UnsafePointer<AnyObject>?, forKeys keys: UnsafePointer<any NSCopying>?, count cnt: Int)
```

## Parameters

`objects`

A C array of values for the new dictionary.

`keys`

A C array of 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 new dictionary.

`cnt`

The number of elements to use from the `keys` and `objects` arrays. `count` must not exceed the number of elements in `objects` or `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 a key or value object is `nil`.

This method is a designated initializer of `NSDictionary`.

## See Also

[`-  initWithObjectsAndKeys:`](/documentation/Foundation/NSDictionary/initWithObjectsAndKeys:)

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

[`-  init`](/documentation/Foundation/NSDictionary/init())

Initializes a newly allocated dictionary.

[`+  dictionaryWithObjects:forKeys:count:`](/documentation/Foundation/NSDictionary/dictionaryWithObjects:forKeys:count:)

Creates a dictionary containing a specified number of objects from a C array.



---

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)