iVars vs @properties in Objective-C

My pondering re: Objective-C the past week:

Do not use instance variables (ivars) when creating or accessing properties.

Always use self + properties to access your variables. For several reasons:

(1) It provides an easy way for other developers involved in the project to debug and set breakpoints.

(2) Properties are ultimately encapsulations of data and methods. Think of it as a universal standard for accessing the data encapsulated by the object (namely the getter and setter methods, and memory offsetting).

(3) If we later decide to implement a feature which uses KVO or KVC (key-value observation & key-vaue coding) the code will not be able to detect a change if we use instance variables.

Oftentimes mobile developers will engage in religious wars over the use of ivars; arguing that because direct access to ivars bypasses method dispatch and thus increases speed and efficiency. This is true. But only by nanoseconds. (source: https://www.bignerdranch.com/blog/should-i-use-a-property-or-an-instance-variable/)

Finally, (since I know I’ve already filled the thread with plenty of* snoretech mumbo jumbo). Declare your properties in the implementation file’s interface. Because of iOS’s non-fragile Application binary Interface (ABI), we don’t have to worry about memory offset issues. Any instance variable will be properly matched with it’s space in memory due to the ABI so there’s no reason to worry about client clashes.

Plus it’s just less ugly.

And I like pretty code.