Copying
public protocol Copying: class
Protocol for classes that can create equivalent duplicates of themselves.
Duplicate is implied to be of the same mutablility as the reciever. The copy returned is immutable if the consideration “immutable vs. mutable” applies to the receiving object; otherwise the exact nature of the copy is determined by the class.
Use Case: Classes that incapsuate information that need to be passed by reference (can’t be structs), but need copying for thread safety, immutablility etc.
-
Creates a copy of the reciever.
Declaration
Swift
var copy: Self { get }