Instance Method インスタンスメソッド

initWithArray:copyItems:

Initializes a newly allocated array using anArray as the source of data objects for the array. 新しく割り当てられた配列を、anArrayをその配列のデータオブジェクトのソースとして使って初期化します。

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. YESならば、arrayの中の各オブジェクトはcopyWithZone:メッセージを受け取って、そのオブジェクトのコピーを作成します—オブジェクトはNSCopyingプロトコルに準拠しなければなりません。管理されたメモリ環境では、これは、そうでなければオブジェクトが受け取るであろうretainメッセージの代わりです。オブジェクトのコピーはそれから返される配列に加えられます。

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. NOならば、それから管理されたメモリ環境ではarrayの各オブジェクトは、それが返される配列に加えられるとき単にretainメッセージを受け取ります。

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. arrayの中のオブジェクト—またはflagYESならば、それらのオブジェクトのコピー—を含むように初期化されたある配列。返されるオブジェクトは、オリジナルのレシーバとは異なるかもしれません。

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. copyWithZone:メソッドは、浅いコピーを行います。あなたが随意の深さのあるコレクションを持つならば、YESflagパラメータに渡すことは表面下の第一階層の不変のコピーを行うことになります。あなたがNOを渡すならば第一階層の可変性は影響を受けません。両方の場合とも、すべてのより深い階層の可変性は影響を受けません。

See Also 参照

Initializing an Array 配列の初期化

Related Documentation 関連文書