ios - Performance: dot syntax VS ivar -


this question has answer here:

@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