Swift copy by reference

whwn we write a = b, we know that may be a coy by value or reference.


but in the middle of code, it is not always immediate if a and b are strict or instances, hence copied by value or reference.


in addition, that makes it less evident to copy the content.


hence my questions :

- are there good practices to make the difference ? I usually name all my classes with a prefix, but the properties are not prefixed, that would make code less lisible

- or can XCode editor write instances in a specific color ?


is there an easy way to copy the content and not the reference In a new object ?One can use a convenient initializer, but that's a limited gain over copying each property. is it possible to define an extension for all classes such as : @a = @b to copy content ?

Your post seems to be filled with instances where you're using the word "copy" where you should be using the word "assign".


Swift lets you define custom operators. But as far as implementing an automatic property value copy operator goes, there are reasons why that's only defined by the language for structures. It's messy enough to do in Objective-C, and Objective-C doesn't have meaningful privacy scoping for objects.

Swift copy by reference
 
 
Q