2

Reading some Objective-C manuals about properties and instance variables, I came across a lot of sentences like

a readwrite property will be backed by an instance variable.

or

Properties are typically backed by an instance variable with a leading underscore, so creating a property called firstName would have a backing instance variable with the name _firstName

What is a "backing" variable? Why does the text use the word "back"? What does it mean exactly?

jscs
  • 63,694
  • 13
  • 151
  • 195
Yong
  • 738
  • 6
  • 19

3 Answers3

3

In the context of implementing properties of Objective-C classes the word "back" means "providing a storage for property's value".

In a sense, the word "back" is opposite of the word "front": the methods implementing the property's getters and setters provide a "front" through which the users of the class interact with the property, while the variable provides the "back" place for the methods to store the value.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
2

A property is syntactic sugar, generally providing accessor methods (getters to read, setters to write) that interface with an instance variable that is synthesized for you. So the instance variable maintains the reference to the underlying object, but the property's accessor methods ensure that all the appropriate memory semantics are followed (amongst other things). So the instance variable is considered to be "backing" the property.

See the declared properties discussion in Apple's Core Competencies document.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
0

Simply put, "backed by" here means "stored to", in a "back-end" sort of saying it.

So

a readwrite property will be backed by an instance variable.

just means

a readwrite property will be stored to an instance variable.

jscs
  • 63,694
  • 13
  • 151
  • 195
John Estropia
  • 17,460
  • 4
  • 46
  • 50