Originally Posted by RonMcMahon
First let me thank you for your very fast response and fairly good explanation. I'm still wrapping my mind around the set and get structure, adjusting it from my use of it in VB6 (yeah, I'm ancient).
Where you lost me is your assertion that @synthesize is no longer necessary if I use @property, which would mean that the code in the book by 'missing' the @synthesize portion is just fine because it still directs readers to use @property (My assumption.)
If this is true, then there is some setting on my Mac that I'm missing because my copy of xCode is saying that it is Version 4.6 (4H127). The iPhone simulator says that it is the iPhone 6.1 Simulator, yet if I remove the line @synthesize textLabel; command from the .m file I get an error saying "Use of undeclared identifier 'textLabel'; did you mean '_textLabel'?" and the system offers to 'fix' it (but the fix doesn't result in a functioning app.)
The only thing that I can think may have to do with this is that your response quotes:
@property (strong, nonatomic) NSString *value;
But the code in the video and book use a weak not strong storage value...
Ok, now I think I see what is going on and is directly related to the newer version of Xcode and iOS 6.
Pre iOS 6 you could say:
textLabel.text = @"some text";
after declaring @property/@synthesize the variable (my use of strong was just an example, and not related to your issue)
But pre iOS 6 saying textLabel.text you were directly accessing that variable, but now with iOS 6 by default the @synthesize is defined as:
So your line textLabel.text = @"some text"; would preferably be
self.textLabel.text = @"some text";
or _textLabel.text = @"some text";
The subject of setters and getters also a long time ago were called modifiers and accessors :)
It was practice for some to directly access a declared instance variable for an object. Some used it and others advised against it, suggesting to use methods instead to either assign or retrieve the values for that variable. This then led to the use of setters and getters.
This also then was suggested to use the self (or this, if you came from a java background) declaration to further refine the use of method access/modify with the variable's value.
Visual Basic programmers I knew at the time just simply directly accessed the declared variables, thus had no need to use any methods to access or modify any declared variables, as developers of regular BASIC back in the A$ days !
So my suggestion if you used @property/@synthesize which establishes the set/get methods for your value interaction, I would also then suggest use:
this to precede the variable to use the set/get structure as I this.textLabel.text = @"some text";
Does that help any ?