Initializes a newly allocated dictionary using the objects contained in another given dictionary.
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
A dictionary containing the keys and values with which to initialize the new dictionary.
true, each object in
copymessage to create a copy of the object—objects must conform to the
NSCopyingprotocol. In a managed memory environment, this is instead of the
retainmessage the object would otherwise receive. The object copy is then added to the returned dictionary.
false, then in a managed memory environment each object in
othersimply receives a
retainmessage when it is added to the returned dictionary.
An initialized object—which might be different than the original receiver—containing the keys and values found in
After an immutable dictionary has been initialized in this way, it cannot be modified.
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.