this question has answer here:
- difference between self.ivar , ivar? 4 answers
@interface person : nsobject @property(nonatomic, assign) cgfloat salary; @end @implementation person - (void)addsalary:(cgfloat)s { _salary += s; **//method 1** self.salary += s; **//method 2** } @end i wonder more efficient between method 1 , 2? compiler optimisation work make them have same performance?
obviously, using _salary faster self.salary , doubt compiler can (in general case) optimization here either because there no guarantee subclass not implement -salary or setsalary: itself. there aspects of key-value notifications. setting self.salary trigger key value observers while using ivar wont. take unless in large , tight loop, won't make noticable difference in app , using self.salary more robust in allows possibility of subclasses. add objective-c runtime efficient in it's dispatch of methods.
Comments
Post a Comment