Initializer

init(set:copyItems:)

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

Declaration

convenience init(set: Set<AnyHashable>, copyItems flag: Bool)

Parameters

set

A set containing objects to add to the new set.

flag

If true, 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 false, 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 copy(with:) method performs a shallow copy. If you have a collection of arbitrary depth, passing true for the flag parameter will perform an immutable copy of the first level below the surface. If you pass false the mutability of the first level is unaffected. In either case, the mutability of all deeper levels is unaffected.

See Also

Initializing a Set

init(array: [Any])

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

init(objects: UnsafePointer<AnyObject>?, count: Int)

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

init(set: Set<AnyHashable>)

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

init()

Initializes a newly allocated set.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software