I am learning Objective-C following a book that is three or four years old (called Tap, Move, Shake). The problem I had is in one of the examples in the book they explain how to create a label and button, then they create the outlet in the .h file, like this:
@property (weak, nonatomic) IBOutlet UILabel *label;
Then they just use the variable label in the .m file within a function, like this:
- (void)generate
{
// pick two numbers between 1 and 9
int a = 1 + arc4random() % 9;
int b = 1 + arc4random() % 9;
// calculate the sum
int sum = a + b;
// create one question
label.text = [NSString stringWithFormat: @"%d + %d", a, b];
// save the answer in the tag property of the label
label.tag = sum;
}
But XCode gives me this error: "Must use struct to refer to type 'label'."
To my understanding, the variable has been already defined in the .h as a local variable so I should be able to retrieve if from the .m, right? (or at least this is what I understand from the book examples).
I've managed to fix this by replacing 'label' by 'self.label' - which makes it work fine now.
I would really appreciate if someone can give me a bit more of information on this.
Thanks a lot in advance!