Why save valueInDollars as value not reference?


#1

I am a novice level programmer, with Objective C / iOS dev being my first language aside from some moderate VBA.

I am still in the process of getting my head properly wrapped around the appropriate use of pointers. My question: When we are setting up the four instance variables in BNRItem.H, why is the int valueInDollars a locally stored value? As opposed to a reference to a value that is set somewhere else.

What I am trying to understand is when to use pointers and when is appropriate to use values. So is the example in the book because of a general principle on how to treat integers, or is it that way to provide an example of a locally stored value vs. pointers to values? The setter / getter methods are handled similarly for the pointers to NSStrings as for this INT so I don’t see the requirements difference.

I hope this is explained correctly here, any clarification (explained like you were talking to a dog or small child) would be much appreciated :slight_smile:

Bonus newbie question
When I am mentally considering pointers, is the use of references in excel a basic appropriate comparison? Excel references as in saying a cells value should always equal what is in cell B1, instead of the value “3.14”. I understand there is a lot more to it than this, but as far as getting the general concept of pointers in Objective C straight in my head that is where I am at now.


#2

I’m gonna come at you with my n00bness, but I’ll have a crack - It’s because valueInDollars is an int, and an int is a primitive - its just a value! No pointers to those.

Am I on the right track?


#3

You are both spot on.

For more details, read this post:
viewtopic.php?f=215&t=6140&p=16750#p16699


#4

Thanks guys! Much appreciated. Your linked post helped alot ibex.

Sorry for the repeat of the question… I checked the chapter 2 board for the question but not chapter 3.