objective-cpropertiesretainretaincount

Are we increasing the reference count here?


I have read several questions but I am still confused. I read this: Objective-C ARC: strong vs retain and weak vs assign and some other questions

When we say: someObject.color = customColor

Are we increasing the reference count of customColor by retaining it or we are creating a new object by copying it? Or none?


Solution

  • That statement is assigning to a property, i.e. calling a setter method on someObject's class. So, that would depend on how the method is implemented. If that is an autogenerated setter method based on the property, then: if it is a copy property, the -copy method will be called on customColor; if strong then it will be retained (i.e. increase the reference count), or if weak or assign then it will not increase the reference count.

    Be aware that on some immutable classes, the -copy method is implemented to just return self, so that will be just like a retain -- it is not always a different object reference.