Had to insert underscore - why?


#1

When I implemented fetchClasses as the book suggested, I got the error message “Use of undeclared identifier ‘activityIndicator’; did you mean ‘_activityIndicator’?” whenever I called activityIndicator or fetchButton. The pre-compiler suggested that I insert the preceding underscores and when I did, everything worked fine but it would not compile until I did that. Why did I have to insert the underscores? Does this have something to do with how those were synthesized? Thanks in advance for any help you can provide. Corrected code below.

- (IBAction)fetchClasses:(id)sender
{
    [_activityIndicator startAnimating];
    [_fetchButton setEnabled:NO];
    
    ScheduleFetcher *fetcher = [[ScheduleFetcher alloc] init];
    [fetcher fetchClassesWithBlock:^(NSArray *classes, NSError *error) {
        [_fetchButton setEnabled:YES];
        [_activityIndicator stopAnimating];
        
        if (classes) {
            ScheduleViewController *svc;
            svc = [[ScheduleViewController alloc] initWithStyle:UITableViewStylePlain];
            [svc setClasses:classes];
            [self.navigationController pushViewController:svc animated:YES];
        } else {
            UIAlertView *alert;
            alert = [[UIAlertView alloc] initWithTitle:@"Error Fetching Classes"
                                               message:[error localizedDescription]
                                              delegate:nil
                                     cancelButtonTitle:@"Dismiss"
                                     otherButtonTitles:nil];
            [alert show];
        }
    }];
    
}

#2

Please provide the code that did not compile, all of it, in order to make it easier to diagnose the mystery.


#3

The way I synthesize my properties is different than the book, and I synthesize as @synthesize = _variableName. If you did the same thing you would have to access the variable through self.variableName or _variableName. I would look at your synthesize statements. Hope this helps.