---
title: "init(objects:forKeys:count:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsdictionary/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.

## Declaration

```swift
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 doc://com.apple.foundation/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

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

### Related Documentation

- [init()](foundation/nsdictionary/init().md)

### Creating a Dictionary from Objects and Keys

- [init(objects:forKeys:)](foundation/nsdictionary/init(objects:forkeys:).md)
- [init(object:forKey:)](foundation/nsdictionary/init(object:forkey:).md)
