Instance Method

initWithSet:copyItems:

Initializes a newly allocated set and adds to it members of another given set.

Declaration

- (instancetype)initWithSet:(NSSet<ObjectType> *)set copyItems:(BOOL)flag;

Parameters

set

A set containing objects to add to the new set.

flag

If YES, each object in set 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 set.

If NO, then in a managed memory environment each object in set simply receives a retain message when it is added to the returned set.

Return Value

An initialized set that contains the members of set. The returned set might be different than the original receiver.

Discussion

After an immutable s 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 a Set

- initWithArray:

Initializes a newly allocated set with the objects that are contained in a given array.

- initWithObjects:

Initializes a newly allocated set with members taken from the specified list of objects.

- initWithObjects:count:

Initializes a newly allocated set with a specified number of objects from a given C array of objects.

- initWithSet:

Initializes a newly allocated set and adds to it objects from another given set.

- init

Initializes a newly allocated set.