Instance Method

initWithArray:copyItems:

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

Declaration

- (instancetype)initWithArray:(NSArray<ObjectType> *)array copyItems:(BOOL)flag;

Parameters

array

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

flag

If YES, each object in array receives a 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 NO, 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 YES, 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 copyWithZone: method performs a shallow copy. If you have a collection of arbitrary depth, passing YES for the flag parameter will perform an immutable copy of the first level below the surface. If you pass NO the mutability of the first level is unaffected. In either case, the mutability of all deeper levels is unaffected.

See Also

Initializing an Array

- init

Initializes a newly allocated array.

- initWithArray:

Initializes a newly allocated array by placing in it the objects contained in a given array.

- initWithContentsOfFile:

Initializes a newly allocated array with the contents of the file specified by a given path.

Deprecated
- initWithContentsOfURL:

Initializes a newly allocated array with the contents of the location specified by a given URL.

Deprecated
- initWithObjects:

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

- initWithObjects:count:

Initializes a newly allocated array to include a given number of objects from a given C array.