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
setreceives a Copywithzone: message to create a copy of the object—objects must conform to theNSCopyingprotocol. In a managed memory environment, this is instead of theretainmessage 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
setsimply receives aretainmessage 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.