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

# init(dictionary:copyItems:)

Initializes a newly allocated dictionary using the objects contained in another given dictionary.

```
convenience init(dictionary otherDictionary: [AnyHashable : Any], copyItems flag: Bool)
```

## Parameters

`otherDictionary`

A dictionary containing the keys and values with which to initialize the new dictionary.

`flag`

If <doc://com.apple.documentation/documentation/Swift/true>, each object in `otherDictionary` receives a <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/copyWithZone:> message to create a copy of the object—objects must conform to the `NSCopying` protocol. In a managed memory environment, this is instead of the `retain` message the object would otherwise receive. The object copy is then added to the returned dictionary.

    If     <doc://com.apple.documentation/documentation/Swift/false>    , then in a managed memory environment each object in     `otherDictionary`     simply receives a     `retain`     message when it is added to the returned dictionary.

## Return Value

An initialized object—which might be different than the original receiver—containing the keys and values found in `otherDictionary`.

## Discussion

After an immutable dictionary has been initialized in this way, it cannot be modified.

The [`copy(with:)`](/documentation/Foundation/NSCopying/copy(with:)) method performs a shallow copy. If you have a collection of arbitrary depth, passing <doc://com.apple.documentation/documentation/Swift/true> for the `flag` parameter will perform an immutable copy of the first level below the surface. If you pass <doc://com.apple.documentation/documentation/Swift/false> the mutability of the first level is unaffected. In either case, the mutability of all deeper levels is unaffected.

---

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)