Hey all, been reading Programing in Objective-C 4th edition and have a really basic question. I think i sort of understand why but am not 100% clear.
when declaring and defining methods, when to use void and when not (and to return a value). The grey area in my my is there because of something like this sample code:
implementation:
-(void) add: (double) value
{ accumulator -= value; }
then in the program itself, once object is made and the following lines:
[deskCal setAccumulator: 100];
[deskCalc add: 200];
NSLog (@"the result if %6", [deskCalc accumulator]);
so my confusion comes when you are declaring the add method as returning no value as i can see by -(void). But is this not returning the value atleast to the object that is receiving the method?
so would (void) not return value in a sense that only the object that receives the method can access that value (private variable?); where as returning the value lets say (int) can return that value to a public variable that anyone can access?
*Ive done examples that return nothing and return a value, but just want to make sure i understand this concept clearly.
Thankyou!!
when declaring and defining methods, when to use void and when not (and to return a value). The grey area in my my is there because of something like this sample code:
implementation:
-(void) add: (double) value
{ accumulator -= value; }
then in the program itself, once object is made and the following lines:
[deskCal setAccumulator: 100];
[deskCalc add: 200];
NSLog (@"the result if %6", [deskCalc accumulator]);
so my confusion comes when you are declaring the add method as returning no value as i can see by -(void). But is this not returning the value atleast to the object that is receiving the method?
so would (void) not return value in a sense that only the object that receives the method can access that value (private variable?); where as returning the value lets say (int) can return that value to a public variable that anyone can access?
*Ive done examples that return nothing and return a value, but just want to make sure i understand this concept clearly.
Thankyou!!