0

If I control-drag a UI element (for instance, a UITableView) from my NIB to my .h file it will generate code like this:

// .h
@property (strong, nonatomic) IBOutlet UITableView *tableView;

// .m
@synthesize tableView;

However, many people seem to think that this would be preferable in the .m file

@synthesize tableView = _tableView;

The reasons are that it forces you to access the ivar via the property setters and getters (or use the dot-syntax self.foo) rather than directly. And it avoids naming conflicts in method names... for instance the tableView in

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Why then does the auto-generated code not follow this convention?

cannyboy
  • 24,180
  • 40
  • 146
  • 252
  • 7
    Because the guy who created the template doesn't like that convention? All of Apple's boiler plate and sample code is a mashup of different coding styles and conventions. – Mark Adams Jan 04 '12 at 00:24

1 Answers1

1

The pace of evolution of Objective C and the Cocoa framework has increased since the introduction of iOS. The answer to this question and insights into properties in Objective C 2.0 are discussed here: Why rename synthesized properties in iOS with leading underscores?

Community
  • 1
  • 1
paul.lander
  • 458
  • 4
  • 5