Those two lines are fundamentally different. The former is essentially a method call to the property's setter method, while the latter is a direct member assignment.
When you do something like self.myObject = x
, that's typically the equivalent of method call of the form [self setMyObject:x]
(although the actual setter method name can be something else if overridden in the property declaration).
In the case of a retain
or copy
property, there is obviously a lot more going on in that method than simple assignment. But even in the case of an assign
property, there are major differences.
When you have a method call, there is always the possibility that the method could be overriden elsewhere in the code. In the case of a direct assignment, it's always an assignment and nothing else.
With the method call, you automatically have support for Key-Value Observing. With the direct assignment, no KVO notifications will be generated.
And finally, as you've noticed, there is obviously a significant performance difference between a direct member assignment and a call to a setter method.