---
title: "init(object:forKey:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsdictionary/init(object:forkey:)"
---

# init(object:forKey:)

Creates a dictionary containing a given key and value.

## Declaration

```swift
convenience init(object: Any, forKey key: any NSCopying)
```

## Parameters

- `object`: The value corresponding to aKey. If this value is nil, an doc://com.apple.foundation/documentation/Foundation/NSExceptionName/invalidArgumentException is raised.
- `key`: The key for anObject. If this value is nil, an doc://com.apple.foundation/documentation/Foundation/NSExceptionName/invalidArgumentException is raised.

## Return Value

Return Value A new dictionary containing a single object, object, for a single key, aKey.

## See Also

### Creating a Dictionary from Objects and Keys

- [init(objects:forKeys:)](foundation/nsdictionary/init(objects:forkeys:).md)
- [init(objects:forKeys:count:)](foundation/nsdictionary/init(objects:forkeys:count:).md)
