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

# init(array:copyItems:)

Initializes a newly allocated array using `anArray` as the source of data objects for the array.

```
convenience init(array: [Any], copyItems flag: Bool)
```

## Parameters

`array`

An array containing the objects with which to initialize the new array.

`flag`

If <doc://com.apple.documentation/documentation/Swift/true>, each object in `array` 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 array.

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

## Return Value

An array initialized to contain the objects—or if `flag` is <doc://com.apple.documentation/documentation/Swift/true>, copies of the objects—in `array`. The returned object might be different than the original receiver.

## Discussion

After an immutable array 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.

## See Also

[`+  arrayWithObject:`](/documentation/Foundation/NSArray/init(object:))

Creates and returns an array containing a given object.

[`-  initWithObjects:`](/documentation/Foundation/NSArray/initWithObjects:)

Initializes a newly allocated array by placing in it the objects in the argument list.



---

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)