iphone - _myObject vs self.myObject -
this question has answer here:
- difference between self.ivar , ivar? 4 answers
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
Post a Comment