Both unshare()
and copy()
are used for copying an array, but I can't see the difference.
As it says on Apple documentation unshare
is to ensure that the copy of the array is unique, so when you call unshare
you get non shared copy of the array, that could be the same array if that was the only reference to the array.
On the other hand copy
forces the copy of the array and returns a new array containing the copied items.
So if you want to have 2 independent copies of the array you should use copy
on other case you can use unsare
to ensure the array has no other references.
unshare()
will do nothing if the callee is already not shared. copy()
will copy it regardless.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With