objective-cfunctionlocal-variablesivar

Assign ivars to local variables within a function?


Is it recommended to assign an instance variable to a local variable within a function in objective c? If it is used several times, it gives a better overview. Also is it faster performance wise?


Solution

  • Performance wise, it is irrelevant unless you measure otherwise. And the chances of the performance difference, if any, actually making a difference is negligible. Depends on how you're are accessing the iVars, though. Direct or via a method call. Via a method call will make a difference if you're doing so a zillion times in a tight loop, say, but that is more indicative of a design problem than a local optimization issue.