So I know that swift array is implemented as struct, and it will do automatically copy by itself.
I have write my class MyClass
and I have implemented copyWithZone
to make copy of it
However, my swift array contains my MyClass
objects, like:
var array = [MyClass]()
when I wan to make a copy of that array like
var anotherArray = array
It still does not call MyClassObject.copyWithZone
, and later if I change the object property in array
, anotherArray
will also reflect the change.
How can I make a copy of that without writing a for loop to iterate every object?
It's not duplicated as deep copy for array of objects in swift because I cannot use struct to rewrite my class.