iphone - _myObject vs self.myObject -


this question has answer here:

when working on game other night, realized increase performance of "tick" code decreasing the number of method calls using _myobject instead of self.myobject.

assuming myobject property, implicitly synthesized compiler, , has value, bottom 1 same thing top one?

// non-arc self.myobject = [self somevalue]; _myobject = [self somevalue]; 

those 2 lines fundamentally different. former method call property's setter method, while latter direct member assignment.

when self.myobject = x, that's typically equivalent of method call of form [self setmyobject:x] (although actual setter method name can else if overridden in property declaration).

in case of retain or copy property, there lot more going on in method simple assignment. in case of assign property, there major differences.

when have method call, there possibility method overriden elsewhere in code. in case of direct assignment, it's assignment , nothing else.

with method call, automatically have support key-value observing. direct assignment, no kvo notifications generated.

and finally, you've noticed, there significant performance difference between direct member assignment , call setter method.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -